From owner-svn-soc-all@FreeBSD.ORG Tue Sep 2 15:03:32 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 81B6619E for ; Tue, 2 Sep 2014 15:03:32 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6289D1305 for ; Tue, 2 Sep 2014 15:03:32 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s82F3WOt049816 for ; Tue, 2 Sep 2014 15:03:32 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s82F3WXe049549 for svn-soc-all@FreeBSD.org; Tue, 2 Sep 2014 15:03:32 GMT (envelope-from dpl@FreeBSD.org) Date: Tue, 2 Sep 2014 15:03:32 GMT Message-Id: <201409021503.s82F3WXe049549@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r273487 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Sep 2014 15:03:32 -0000 Author: dpl Date: Tue Sep 2 15:03:31 2014 New Revision: 273487 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=273487 Log: Corrected LLVM code, now assertions are always right. Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Tue Sep 2 14:27:12 2014 (r273486) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Tue Sep 2 15:03:31 2014 (r273487) @@ -78,12 +78,12 @@ Value *Match; Value *L; Value *Done; - Value *F_pos; + Value *FPos; Value *Retval; Value *Cmd; - Value *Cmdlen; + Value *CmdLen; Value *Tablearg; - Value *Skip_or; + Value *SkipOr; Value *F; // Packet matching variables. @@ -289,17 +289,17 @@ Done = Irb.CreateAlloca(Int32Ty); Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Done); - F_pos = Irb.CreateAlloca(Int32Ty); - Irb.CreateStore(ConstantInt::get(Int32Ty, 0), F_pos); + FPos = Irb.CreateAlloca(Int32Ty); + Irb.CreateStore(ConstantInt::get(Int32Ty, 0), FPos); Retval = Irb.CreateAlloca(Int32Ty); Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Retval); - Cmd = Irb.CreateAlloca(Ipfw_insnTy); + Cmd = Irb.CreateAlloca(Ipfw_insnPtrTy); Tablearg = Irb.CreateAlloca(Int32Ty); - Cmdlen = Irb.CreateAlloca(Int32Ty); - Skip_or = Irb.CreateAlloca(Int32Ty); - F = Irb.CreateAlloca(Ip_fwTy); + CmdLen = Irb.CreateAlloca(Int32Ty); + SkipOr = Irb.CreateAlloca(Int32Ty); + F = Irb.CreateAlloca(Ip_fwPtrTy); // m = args->m (idx: 0) MPtr = Irb.CreateAlloca(MbufPtrTy); @@ -390,33 +390,11 @@ // If it returns one, goto pullup_failed. // Else, goto first rule. Value *Ip = Irb.CreateLoad(IpPtr); - - Args->getType()->dump(); - Ip->getType()->dump(); - M->getType()->dump(); - Src_ip->getType()->dump(); - Dst_ip->getType()->dump(); - Src_port->getType()->dump(); - Dst_port->getType()->dump(); - Etype->getType()->dump(); - Ext_hd->getType()->dump(); - Iplen->getType()->dump(); - Pktlen->getType()->dump(); - Is_ipv4->getType()->dump(); - Is_ipv6->getType()->dump(); - Hlen->getType()->dump(); - Proto->getType()->dump(); - Icmp6_type->getType()->dump(); - Ip6f_mf->getType()->dump(); - Offset->getType()->dump(); - Ulp->getType()->dump(); - - InspectPkt->dump(); + Value *UlpL = Irb.CreateLoad(Ulp); Value *InspectPktCall = Irb.CreateCall(InspectPkt, {Args, Ip, M, Src_ip, Dst_ip, Src_port, Dst_port, Etype, Ext_hd, Iplen, Pktlen, Is_ipv4, - Is_ipv6, Hlen, Proto, Icmp6_type, Ip6f_mf, Offset, Ulp}); - InspectPktCall->dump(); + Is_ipv6, Hlen, Proto, Icmp6_type, Ip6f_mf, Offset, UlpL}); Value *Cond = Irb.CreateICmpEQ(InspectPktCall, ConstantInt::get(Int32Ty, 1)); Irb.CreateCondBr(Cond, Pullup_failed, Check_tag); @@ -428,7 +406,7 @@ BasicBlock *print = BasicBlock::Create(Con, "print", Func); BasicBlock *ret = BasicBlock::Create(Con, "ret", Func); - Value *is_verbose, *str, *Comp; + Value *Is_verbose, *Str, *Comp; // VNET_DECLARE(int, fw_verbose); @@ -440,18 +418,20 @@ // printf("ipfw: pullup failed\n"); // return (IP_FW_DENY); - is_verbose = mod->getGlobalVariable("fw_verbose"); - str = Irb.CreateGlobalString("ipfw: pullup failed\n"); + Is_verbose = mod->getGlobalVariable("fw_verbose"); + Str = Irb.CreateGlobalString("ipfw: pullup failed\n"); Irb.SetInsertPoint(Pullup_failed); // if (V_fw_verbose) - Comp = Irb.CreateICmpEQ(is_verbose, ConstantInt::get(Int32Ty, 0)); + Value *Is_verboseL = Irb.CreateLoad(Is_verbose); + Comp = Irb.CreateICmpEQ(Is_verboseL, ConstantInt::get(Int32Ty, 0)); Irb.CreateCondBr(Comp, ret, print); // printf("ipfw: pullup failed\n"); Irb.SetInsertPoint(print); - Irb.CreateCall(PrintfFunc, str); + Value *StrFirstElement = Irb.CreateStructGEP(Str, 0); + Irb.CreateCall(PrintfFunc, StrFirstElement); Irb.CreateBr(ret); // return (IP_FW_DENY); @@ -490,27 +470,34 @@ // if (args->rule.slot) Value *Rule = Irb.CreateStructGEP(Args, 4); Value *Slot = Irb.CreateStructGEP(Rule, 0); - Comp = Irb.CreateICmpEQ(Slot, ConstantInt::get(Int32Ty, 0)); + Value *SlotValue = Irb.CreateLoad(Slot); + Comp = Irb.CreateICmpEQ(SlotValue, ConstantInt::get(Int32Ty, 0)); Irb.CreateCondBr(Comp, Nottagged, Tagged); Irb.SetInsertPoint(Tagged); // if (args->rule.chain_id == chain->id) - Value *Chain_id = Irb.CreateStructGEP(Rule, 3); - Value *Id = Irb.CreateInBoundsGEP(Chain, ConstantInt::get(Int32Ty, 12)); - Comp = Irb.CreateICmpEQ(Chain_id, Id); + Value *ChainId = Irb.CreateStructGEP(Rule, 3); + Value *Id = Irb.CreateStructGEP(Chain, 12); + Value *ChainIdL = Irb.CreateLoad(ChainId); + Value *IdL = Irb.CreateLoad(Id); + Comp = Irb.CreateICmpEQ(ChainIdL, IdL); Irb.CreateCondBr(Comp, Jt, Jf); // f_pos = args->rule.slot; Irb.SetInsertPoint(Jt); - Irb.CreateStore(Slot, F_pos); + Irb.CreateStore(SlotValue, FPos); Irb.CreateBr(Nottagged); // else fpos = ipfw_find_rule(chain, args->rule.rulenum, args->rule.rule_id) Irb.SetInsertPoint(Jf); Value *Rulenum = Irb.CreateStructGEP(Rule, 1); + Value *RulenumL = Irb.CreateLoad(Rulenum); + Value *RuleId = Irb.CreateStructGEP(Rule, 2); - Value *FindRuleCall = Irb.CreateCall3(Ipfw_find_rule, Chain, Rulenum, RuleId); - Irb.CreateStore(FindRuleCall, F_pos); + Value *RuleIdL = Irb.CreateLoad(RuleId); + + Value *FindRuleCall = Irb.CreateCall3(Ipfw_find_rule, Chain, RulenumL, RuleIdL); + Irb.CreateStore(FindRuleCall, FPos); // Branch to Nottagged because it // only finishes the entry BasicBlock. @@ -529,7 +516,7 @@ BasicBlock *jt = BasicBlock::Create(Con, "jt", Func); BasicBlock *jf = BasicBlock::Create(Con, "jf", Func); - Value *set_disable = mod->getGlobalVariable("set_disable"); + Value *SetDisable = mod->getGlobalVariable("set_disable"); // All this variables are already allocated. // ipfw_insn *cmd; @@ -548,24 +535,28 @@ // f = chain->map[f_pos]; idxs: 5, f_pos Value *MapPtr = Irb.CreateStructGEP(Chain, 5); Value *Map = Irb.CreateLoad(MapPtr); - Value *MapFPos = Irb.CreateInBoundsGEP(Map, F_pos); - Irb.CreateStore(MapFPos, F); + Value *MapFPos = Irb.CreateInBoundsGEP(Map, FPos); + Value *MapFPosL = Irb.CreateLoad(MapFPos); + Irb.CreateStore(MapFPosL, F); // if (V_set_disable & (1 << f->set) ) - Value *Set = Irb.CreateStructGEP(F, 5); - Value *ShiftedSet = Irb.CreateShl(ConstantInt::get(Int32Ty, 1), Set); - Value *AndOp = Irb.CreateAnd(set_disable, ShiftedSet); + Value *FL = Irb.CreateLoad(F); + Value *Set = Irb.CreateStructGEP(FL, 5); + Value *SetL = Irb.CreateLoad(Set); //uint8 + Value *ShiftedSet = Irb.CreateShl(ConstantInt::get(Int8Ty, 1), SetL); + Value *SetDisableL = Irb.CreateLoad(SetDisable); + Value *ShiftedSet32 = Irb.CreateZExt(ShiftedSet, Int32Ty); + Value *AndOp = Irb.CreateAnd(SetDisableL, ShiftedSet32); Value *Comp = Irb.CreateICmpNE(AndOp, ConstantInt::get(Int32Ty, 0)); Irb.CreateCondBr(Comp, jt, jf); - Irb.SetInsertPoint(jt); // continue; Irb.CreateBr(nextRule(rulenumber+1)); // skip_or = 0; Irb.SetInsertPoint(jf); - Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Skip_or); + Irb.CreateStore(ConstantInt::get(Int32Ty, 0), SkipOr); Irb.CreateBr(Inner_for_prologue); } @@ -595,23 +586,32 @@ Irb.SetInsertPoint(Inner_for_prologue); // l = f->cmd_len; - // XXX - ask David about types. int l; uint16_t cmd_len; - Value *CmdLen = Irb.CreateStructGEP(F, 3); - Irb.CreateStore(CmdLen, L); + Value *FL = Irb.CreateLoad(F); + Value *FCmdLen = Irb.CreateStructGEP(FL, 3); + Value *FCmdLenL = Irb.CreateLoad(FCmdLen); + Value *FCmdLenL32 = Irb.CreateZExt(FCmdLenL, Int32Ty); + Irb.CreateStore(FCmdLenL32, L); // cmd = f->cmd; - Value *FCmd = Irb.CreateStructGEP(F, 11); - Irb.CreateStore(FCmd, Cmd); + Value *FCmd = Irb.CreateStructGEP(FL, 11); + Value *FCmdL = Irb.CreateLoad(FCmd); + FCmd = Irb.CreateExtractValue(FCmdL, 0); + Value *CmdL = Irb.CreateLoad(Cmd); + Irb.CreateStore(FCmd, CmdL); // int match; Match = Irb.CreateAlloca(Int32Ty); + // int cmdlen; // cmdlen = ((cmd)->len & F_LEN_MASK); - Value *Len = Irb.CreateStructGEP(Cmd, 1); + Value *LenPtr = Irb.CreateStructGEP(CmdL, 1); + Value *Len = Irb.CreateLoad(LenPtr); AndOp = Irb.CreateAnd(Len, ConstantInt::get(Int8Ty, F_LEN_MASK)); - Irb.CreateStore(AndOp, Cmdlen); + Value *AndOp32 = Irb.CreateSExt(AndOp, Int32Ty); + Irb.CreateStore(AndOp32, CmdLen); // if (skip_or) - Comp = Irb.CreateICmpNE(Skip_or, ConstantInt::get(Int32Ty, 0)); + Value *SkipOrL = Irb.CreateLoad(SkipOr); + Comp = Irb.CreateICmpNE(SkipOrL, ConstantInt::get(Int32Ty, 0)); Irb.CreateCondBr(Comp, firstt, firstf); Irb.SetInsertPoint(firstt); @@ -622,7 +622,7 @@ Irb.SetInsertPoint(secondt); // skip_or = 0; - Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Skip_or); + Irb.CreateStore(ConstantInt::get(Int32Ty, 0), SkipOr); Irb.CreateBr(secondf); Irb.SetInsertPoint(secondf); @@ -652,8 +652,18 @@ // This are the increments of the for loop. // l -= cmdlen, cmd += cmdlen; - Irb.CreateStore(Irb.CreateNSWSub(L, Cmdlen), L); - Irb.CreateStore(Irb.CreateAdd(Cmd, Cmdlen), Cmd); + Value *LL = Irb.CreateLoad(L); + Value *CmdLenL = Irb.CreateLoad(CmdLen); + Value *Sub = Irb.CreateNSWSub(LL, CmdLenL); + Irb.CreateStore(Sub, L); + + // TODO -- Should ensure correctness of code. + // ipfw_insn *cmd; Add to pointer. + // Note: Since LLVM can't add to a ptr, we can use GEP with casted Ptr. + // cmd += cmdlen; + Value *CmdL = Irb.CreateLoad(Cmd); + Value *Add = Irb.CreateInBoundsGEP(CmdL, CmdLenL); + Irb.CreateStore(Add, Cmd); // if (cmd->len & F_NOT) // match = !match; @@ -669,15 +679,17 @@ Irb.SetInsertPoint(Inner_for_epilogue); // if (cmd->len & F_NOT) - Value *Len = Irb.CreateStructGEP(Cmd, 1); - AndOp = Irb.CreateAnd(Len, ConstantInt::get(Int8Ty, F_NOT)); - Comp = Irb.CreateICmpNE(AndOp, ConstantInt::get(Int32Ty, 0)); + Value *Len = Irb.CreateStructGEP(CmdL, 1); + Value *LenL = Irb.CreateLoad(Len); + AndOp = Irb.CreateAnd(LenL, ConstantInt::get(Int8Ty, F_NOT)); + Comp = Irb.CreateICmpNE(AndOp, ConstantInt::get(Int8Ty, 0)); Irb.CreateCondBr(Comp, jt, sec_cond); Irb.SetInsertPoint(jt); // match = !match; // match = ((match)?0:1); - Comp = Irb.CreateICmpNE(Match, ConstantInt::get(Int32Ty, 0)); + Value *MatchL = Irb.CreateLoad(Match); + Comp = Irb.CreateICmpNE(MatchL, ConstantInt::get(Int32Ty, 0)); Irb.CreateCondBr(Comp, matchnz, matchz); Irb.SetInsertPoint(matchnz); @@ -690,25 +702,25 @@ Irb.SetInsertPoint(sec_cond); // if (match) - Comp = Irb.CreateICmpNE(Match, ConstantInt::get(Int32Ty, 0)); + Comp = Irb.CreateICmpNE(MatchL, ConstantInt::get(Int32Ty, 0)); Irb.CreateCondBr(Comp, matchnotzero, matchzero); Irb.SetInsertPoint(matchnotzero); // if (cmd->len & F_OR) - AndOp = Irb.CreateAnd(Len, ConstantInt::get(Int8Ty, F_OR)); - Comp = Irb.CreateICmpNE(AndOp, ConstantInt::get(Int32Ty, 0)); + AndOp = Irb.CreateAnd(LenL, ConstantInt::get(Int8Ty, F_OR)); + Comp = Irb.CreateICmpNE(AndOp, ConstantInt::get(Int8Ty, 0)); Irb.CreateCondBr(Comp, is_or, Outer_for_epilogue); Irb.SetInsertPoint(is_or); // skip_or = 1; - Irb.CreateStore(ConstantInt::get(Int32Ty, 1), Skip_or); + Irb.CreateStore(ConstantInt::get(Int32Ty, 1), SkipOr); Irb.CreateBr(Outer_for_epilogue); Irb.SetInsertPoint(matchzero); // if (!(cmd->len & F_OR)) /* not an OR block, */ // break; - AndOp = Irb.CreateAnd(Len, ConstantInt::get(Int8Ty, F_OR)); - Comp = Irb.CreateICmpEQ(AndOp, ConstantInt::get(Int32Ty, 0)); + AndOp = Irb.CreateAnd(LenL, ConstantInt::get(Int8Ty, F_OR)); + Comp = Irb.CreateICmpEQ(AndOp, ConstantInt::get(Int8Ty, 0)); Irb.CreateCondBr(Comp, nextRule(rulenumber+1) /* break */, Outer_for_epilogue); } @@ -720,23 +732,25 @@ Irb.SetInsertPoint(Outer_for_epilogue); // f_pos++, increment of the for loop. - Value *AddOp = Irb.CreateAdd(F_pos, ConstantInt::get(Int32Ty, 1)); - Irb.CreateStore(AddOp, F_pos); + Value *FPosL = Irb.CreateLoad(FPos); + Value *AddOp = Irb.CreateAdd(FPosL, ConstantInt::get(Int32Ty, 1)); + Irb.CreateStore(AddOp, FPos); // if (done) // break; - Value *Comp = Irb.CreateICmpNE(Done, ConstantInt::get(Int32Ty, 0)); + Value *DoneL = Irb.CreateLoad(Done); + Value *Comp = Irb.CreateICmpNE(DoneL, ConstantInt::get(Int32Ty, 0)); Irb.CreateCondBr(Comp, End, nextRule(rulenumber+1)); } void emit_end() { - Value *rule, *time_uptime, *str; + Value *Rule, *TimeUptime, *Str; - BasicBlock *jt = BasicBlock::Create(Con, "jt", Func); - BasicBlock *jf = BasicBlock::Create(Con, "jf", Func); - BasicBlock *ret = BasicBlock::Create(Con, "ret", Func); + BasicBlock *Jt = BasicBlock::Create(Con, "jt", Func); + BasicBlock *Jf = BasicBlock::Create(Con, "jf", Func); + BasicBlock *Ret = BasicBlock::Create(Con, "ret", Func); Value *Comp, *AddOp; // if (done) { @@ -759,47 +773,56 @@ Irb.SetInsertPoint(End); // We need to get the timestamp variable. - time_uptime = mod->getGlobalVariable("time_uptime"); - str = Irb.CreateGlobalString("ipfw: ouch!, skip past end of rules, denying packet\n"); + TimeUptime = mod->getGlobalVariable("time_uptime"); + Str = Irb.CreateGlobalString("ipfw: ouch!, skip past end of rules, denying packet\n"); // if (done) - Comp = Irb.CreateICmpNE(Done, ConstantInt::get(Int32Ty, 0)); - Irb.CreateCondBr(Comp, jt, jf); + Value *DoneL = Irb.CreateLoad(Done); + Comp = Irb.CreateICmpNE(DoneL, ConstantInt::get(Int32Ty, 0)); + Irb.CreateCondBr(Comp, Jt, Jf); - Irb.SetInsertPoint(jt); + Irb.SetInsertPoint(Jt); // struct ip_fw *rule = chain->map[f_pos]; - rule = Irb.CreateAlloca(Ip_fwPtrTy); + Rule = Irb.CreateAlloca(Ip_fwPtrTy); Value *MapPtr = Irb.CreateStructGEP(Chain, 5); Value *Map = Irb.CreateLoad(MapPtr); - Value *MapFPos = Irb.CreateInBoundsGEP(Map, F_pos); - Irb.CreateStore(MapFPos, rule); + Value *MapFPos = Irb.CreateInBoundsGEP(Map, FPos); + Value *MapFPosL = Irb.CreateLoad(MapFPos); + Irb.CreateStore(MapFPosL, Rule); // uint64_t pcnt; // (rule)->pcnt++; - Value *RuleL = Irb.CreateLoad(rule); + Value *RuleL = Irb.CreateLoad(Rule); Value *Pcnt = Irb.CreateStructGEP(RuleL, 8); - AddOp = Irb.CreateAdd(Pcnt, ConstantInt::get(Pcnt->getType(), 1)); + Value *PcntL = Irb.CreateLoad(Pcnt); + AddOp = Irb.CreateAdd(PcntL, ConstantInt::get(PcntL->getType(), 1)); Irb.CreateStore(AddOp, Pcnt); // uint64_t bnct; + // int32_t pktlen // (rule)->bcnt += pktlen; - // XXX pktlen->getType(): Int32Ty - Value *bcnt = Irb.CreateStructGEP(RuleL, 9); - AddOp = Irb.CreateAdd(bcnt, Pktlen); - Irb.CreateStore(AddOp, bcnt); + Value *Bcnt = Irb.CreateStructGEP(RuleL, 9); + Value *BcntL = Irb.CreateLoad(Bcnt); + Value *PktlenL = Irb.CreateLoad(Pktlen); + Value *PktlenL64 = Irb.CreateZExt(PktlenL, Int64Ty); + AddOp = Irb.CreateAdd(BcntL, PktlenL64); + Irb.CreateStore(AddOp, Bcnt); + // We have to fit 64 bits into 32 // (rule)->timestamp = time_uptime; // uInt32_t timestamp; - // XXX timestamp->getType(): Int32Ty - // XXX time_uptime: int64Ty - Value *timestamp = Irb.CreateStructGEP(RuleL, 10); - Irb.CreateStore(time_uptime, timestamp); + // int64_t time_uptime; + Value *TimeUptimeL = Irb.CreateLoad(TimeUptime); + Value *TimeUptimeL32 = Irb.CreateTrunc(TimeUptimeL, Int32Ty); + Value *Timestamp = Irb.CreateStructGEP(RuleL, 10); + Irb.CreateStore(TimeUptimeL32, Timestamp); - Irb.SetInsertPoint(jf); + Irb.SetInsertPoint(Jf); // retval = IP_FW_DENY; // printf("ipfw: ouch!, skip past end of rules, denying packet\n"); Irb.CreateStore(ConstantInt::get(Int32Ty, IP_FW_DENY), Retval); - Irb.CreateCall(PrintfFunc, str); + Value *StrFirstElement = Irb.CreateStructGEP(Str, 0); + Irb.CreateCall(PrintfFunc, StrFirstElement); #ifndef __FreeBSD__ Irb.CreateBr(ret); #endif @@ -807,17 +830,18 @@ #ifdef __FreeBSD__ { Irb.SetInsertPoint(End); - BasicBlock *cache_nnull; + BasicBlock *CacheNN = BasicBlock::Create(Con, "cachennull", Func); // if (ucred_cache != NULL) - Comp = Irb.CreateICmpNE(Ucred_cache, ConstantPointerNull::get(UcredPtrTy)); - Irb.CreateCondBr(Comp, cache_nnull, ret); + Comp = Irb.CreateICmpNE(Ucred_cache, + ConstantPointerNull::get(UcredPtrTy)); + Irb.CreateCondBr(Comp, CacheNN, Ret); - Irb.SetInsertPoint(cache_nnull); - Irb.CreateBr(ret); + Irb.SetInsertPoint(CacheNN); + Irb.CreateBr(Ret); } #endif - Irb.SetInsertPoint(ret); + Irb.SetInsertPoint(Ret); Irb.CreateRet(Retval); } @@ -840,16 +864,16 @@ // The entry basic block contains all the initialization // and allocation of resources, and a basic check done // before start emmiting the rules code. - Entry = BasicBlock::Create(Con, "entry", Func); - Check_tag = BasicBlock::Create(Con, "check_tag", Func); - End = BasicBlock::Create(Con, "end", Func); + Entry = BasicBlock::Create(Con, "Entry", Func); + End = BasicBlock::Create(Con, "End", Func); + Check_tag = BasicBlock::Create(Con, "CheckTag", Func); // This is equivalent to the pullup_failed tag. - Pullup_failed = BasicBlock::Create(Con, "pullup_failed", Func); + Pullup_failed = BasicBlock::Create(Con, "PullupFailed", Func); //Snippets of code to be executed when iterating through the rules. - Outer_for_prologue = BasicBlock::Create(Con, "outer_for_prologue", Func); - Inner_for_prologue = BasicBlock::Create(Con, "inner_for_prologue", Func); - Inner_for_epilogue = BasicBlock::Create(Con, "inner_for_epilogue", Func); - Outer_for_epilogue = BasicBlock::Create(Con, "outer_for_epilogue", Func); + Outer_for_prologue = BasicBlock::Create(Con, "OuterForPrologue", Func); + Inner_for_prologue = BasicBlock::Create(Con, "InnerForPrologue", Func); + Inner_for_epilogue = BasicBlock::Create(Con, "InnerForEpilogue", Func); + Outer_for_epilogue = BasicBlock::Create(Con, "OuterForEpilogue", Func); // Get struct types, and store vars setEnv(); @@ -875,10 +899,16 @@ funcptr compile() { + std::string errstr; + std::string comperr = "Compilation error\n"; + // Check correctness. verifyFunction(*Func); verifyModule(*mod); + InitializeNativeTarget(); + LLVMLinkInJIT(); + //Optimise PassManagerBuilder PMBuilder; PMBuilder.OptLevel = 0; @@ -891,13 +921,10 @@ PerFunctionPasses->doFinalization(); delete PerFunctionPasses; - //printf("\n\n\n\n"); - //mod->getFunction("ipfw_chk_jit")->dump(); - // Module passes PassManager *PerModulePasses = new PassManager(); PMBuilder.populateModulePassManager(*PerModulePasses); - PerModulePasses->run(*mod); + //PerModulePasses->run(*mod); delete PerModulePasses; // We don't need it anymore. @@ -905,11 +932,7 @@ vf->eraseFromParent(); //Compile - std::string errstr; - std::string comperr = "Compilation error\n"; - EngineBuilder EB = EngineBuilder(std::unique_ptr(mod)); - EB.setEngineKind(EngineKind::Kind::JIT); EB.setErrorStr(&comperr); ExecutionEngine *EE = EB.create(); @@ -918,7 +941,7 @@ exit(1); } - printf("Function ptr: %p\n", (void *)EE->getFunctionAddress("ipfw_chk_jit")); + printf("FuncPtr: %p\n", (void *)EE->getFunctionAddress("ipfw_chk_jit")); err(1,"null"); return (funcptr)EE->getFunctionAddress("ipfw_chk_jit"); } @@ -991,12 +1014,17 @@ // proto == IPPROTO_UDP) // *match = 0; + // if (offset != 0) + // return; + + // if (proto == IPPROTO_TCP || + // proto == IPPROTO_UDP) + // *match = 0; } void emit_recv() { - // XXX Check correctness. //*match = iface_match(m->m_pkthdr.rcvif, (ipfw_insn_if *)cmd, chain, tablearg); Value *rcvif = Irb.CreateStructGEP(Irb.CreateStructGEP(Irb.CreateLoad(MPtr), 5), 0); Value *cmdc = Irb.CreateBitCast(Cmd, Ipfw_insn_ifPtrTy); @@ -1012,7 +1040,6 @@ Value *IfaceMatchCall = Irb.CreateCall4(Iface_match, Oif, Cmdc, Chain, Tablearg); Irb.CreateStore(IfaceMatchCall, Match); } - }; extern "C" funcptr From owner-svn-soc-all@FreeBSD.ORG Tue Sep 2 19:04:05 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id AB0778EE for ; Tue, 2 Sep 2014 19:04:05 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 96D7B14ED for ; Tue, 2 Sep 2014 19:04:05 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s82J45k0031233 for ; Tue, 2 Sep 2014 19:04:05 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s82J453K031176 for svn-soc-all@FreeBSD.org; Tue, 2 Sep 2014 19:04:05 GMT (envelope-from op@FreeBSD.org) Date: Tue, 2 Sep 2014 19:04:05 GMT Message-Id: <201409021904.s82J453K031176@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r273495 - soc2014/op/freebsd-base/sys/x86/include MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Sep 2014 19:04:05 -0000 Author: op Date: Tue Sep 2 19:04:04 2014 New Revision: 273495 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=273495 Log: SMAP: fix build world Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/smap+kpatch Modified: soc2014/op/freebsd-base/sys/x86/include/selfpatch-asmacros.h Modified: soc2014/op/freebsd-base/sys/x86/include/selfpatch-asmacros.h ============================================================================== --- soc2014/op/freebsd-base/sys/x86/include/selfpatch-asmacros.h Tue Sep 2 18:57:19 2014 (r273494) +++ soc2014/op/freebsd-base/sys/x86/include/selfpatch-asmacros.h Tue Sep 2 19:04:04 2014 (r273495) @@ -30,7 +30,9 @@ #ifndef __X86_SELFPATCH_ASMACROS_H__ #define __X86_SELFPATCH_ASMACROS_H__ +#ifdef _KERNEL #include "opt_cpu.h" +#endif #define KSP_CPUID 1 #define KSP_CPUID2 2 From owner-svn-soc-all@FreeBSD.ORG Wed Sep 3 10:22:50 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 723EF9D6 for ; Wed, 3 Sep 2014 10:22:50 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5E2B81FE7 for ; Wed, 3 Sep 2014 10:22:50 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s83AMovc046768 for ; Wed, 3 Sep 2014 10:22:50 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s83AMnh1046766 for svn-soc-all@FreeBSD.org; Wed, 3 Sep 2014 10:22:49 GMT (envelope-from dpl@FreeBSD.org) Date: Wed, 3 Sep 2014 10:22:49 GMT Message-Id: <201409031022.s83AMnh1046766@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r273534 - soc2014/dpl/netmap-ipfwjit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Sep 2014 10:22:50 -0000 Author: dpl Date: Wed Sep 3 10:22:49 2014 New Revision: 273534 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=273534 Log: Delete bitcode when make clean Modified: soc2014/dpl/netmap-ipfwjit/Makefile Modified: soc2014/dpl/netmap-ipfwjit/Makefile ============================================================================== --- soc2014/dpl/netmap-ipfwjit/Makefile Wed Sep 3 09:58:59 2014 (r273533) +++ soc2014/dpl/netmap-ipfwjit/Makefile Wed Sep 3 10:22:49 2014 (r273534) @@ -26,7 +26,7 @@ clean: -@rm -rf $(OBJDIR) kipfw @(cd ipfw && $(MAKE) clean ) - @rm -f ./ip_fw_rules.bc + -@rm -f *.bc tgz: @$(MAKE) clean From owner-svn-soc-all@FreeBSD.ORG Wed Sep 3 10:32:21 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 52334B9C for ; Wed, 3 Sep 2014 10:32:21 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 22294117C for ; Wed, 3 Sep 2014 10:32:21 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s83AWLQk067477 for ; Wed, 3 Sep 2014 10:32:21 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s83AWKTe067369 for svn-soc-all@FreeBSD.org; Wed, 3 Sep 2014 10:32:20 GMT (envelope-from dpl@FreeBSD.org) Date: Wed, 3 Sep 2014 10:32:20 GMT Message-Id: <201409031032.s83AWKTe067369@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r273535 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Sep 2014 10:32:21 -0000 Author: dpl Date: Wed Sep 3 10:32:20 2014 New Revision: 273535 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=273535 Log: No assertions, cleaned the code. Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Wed Sep 3 10:22:49 2014 (r273534) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Wed Sep 3 10:32:20 2014 (r273535) @@ -62,13 +62,10 @@ PointerType *Int8PtrTy; // Basic blocks used - BasicBlock *Entry, *End; - BasicBlock *Pullup_failed; - BasicBlock *Check_tag; - BasicBlock *Outer_for_prologue; - BasicBlock *Inner_for_prologue; - BasicBlock *Outer_for_epilogue; - BasicBlock *Inner_for_epilogue; + BasicBlock *Entry; + BasicBlock *End; + BasicBlock *PullupFailed; + BasicBlock *CheckTag; // JIT Compiled Vars // These are the function arguments. @@ -172,15 +169,15 @@ Module * loadBitcode(std::string name) { - auto buffer = MemoryBuffer::getFile(name); - if (buffer.getError()){ - std::cerr << "Failed to open bitcode: " << buffer.getError() << "\n"; + auto buff = MemoryBuffer::getFile(name); + if (buff.getError()){ + std::cerr << "Failed to open bitcode: " << buff.getError() << "\n"; return (NULL); } - auto modptr = parseBitcodeFile(buffer.get().get(), Con); + auto modptr = parseBitcodeFile(buff.get().get(), Con); if ((modptr.getError())){ - std::cerr << "Failed to parse bitcode: " << buffer.getError() << "\n"; + std::cerr << "Failed to parse bitcode: " << buff.getError() << "\n"; return (NULL); } return (modptr.get()); @@ -397,9 +394,10 @@ Is_ipv6, Hlen, Proto, Icmp6_type, Ip6f_mf, Offset, UlpL}); Value *Cond = Irb.CreateICmpEQ(InspectPktCall, ConstantInt::get(Int32Ty, 1)); - Irb.CreateCondBr(Cond, Pullup_failed, Check_tag); + Irb.CreateCondBr(Cond, PullupFailed, CheckTag); } + // This is equivalent to the pullup_failed tag. void emit_pullup_failed() { @@ -421,7 +419,7 @@ Is_verbose = mod->getGlobalVariable("fw_verbose"); Str = Irb.CreateGlobalString("ipfw: pullup failed\n"); - Irb.SetInsertPoint(Pullup_failed); + Irb.SetInsertPoint(PullupFailed); // if (V_fw_verbose) Value *Is_verboseL = Irb.CreateLoad(Is_verbose); @@ -449,7 +447,7 @@ Value *Comp; - Irb.SetInsertPoint(Check_tag); + Irb.SetInsertPoint(CheckTag); // if (args->rule.slot) { // /* @@ -510,6 +508,111 @@ Irb.CreateBr(rules.front()); } + public: + ipfwJIT(int rulesnumber): Irb(Con) + { + // Create the module and load the code. + mod = loadBitcode("rules.bc"); + + Func = mod->getFunction("ipfw_chk_jit"); + Func->setLinkage(GlobalValue::ExternalLinkage); + // Create static BasicBlocks. + // The entry basic block contains all the initialization + // and allocation of resources, and a basic check done + // before start emmiting the rules code. + Entry = BasicBlock::Create(Con, "Entry", Func); + End = BasicBlock::Create(Con, "End", Func); + CheckTag = BasicBlock::Create(Con, "CheckTag", Func); + PullupFailed = BasicBlock::Create(Con, "PullupFailed", Func); + + + // Get struct types, and store vars + setEnv(); + + // Start compilation + allocaAndInit(); + + // Initialize the vector. + rules = std::vector(rulesnumber); + for (auto &i: rules){ + i = BasicBlock::Create(Con, "rule", Func); + } + + emit_check_tag(); + emit_pullup_failed(); + } + ~ipfwJIT() + { + if (mod) + delete mod; + } + + funcptr + compile() + { + InitializeNativeTarget(); + LLVMLinkInJIT(); + +// //Optimise +// PassManagerBuilder PMBuilder; +// PMBuilder.OptLevel = 1; +// PMBuilder.Inliner = createFunctionInliningPass(275); + +// // Function passes +// FunctionPassManager *PerFunctionPasses = new FunctionPassManager(mod); +// PMBuilder.populateFunctionPassManager(*PerFunctionPasses); +// PerFunctionPasses->run(*Func); +// PerFunctionPasses->doFinalization(); +// delete PerFunctionPasses; + +// printf("Done optimizing Function\n"); + +// // Module passes +// PassManager *PerModulePasses = new PassManager(); +// PMBuilder.populateModulePassManager(*PerModulePasses); +// PerModulePasses->run(*mod); +// delete PerModulePasses; + +// printf("Done optimizing Module\n"); + + // // We don't need it anymore. + // Function *vf = mod->getFunction("voidfunction"); + // vf->eraseFromParent(); + // printf("Done erasing voidfunction\n"); + + //Compile + std::string comperr = "Compilation error\n"; + std::string errstr; + + EngineBuilder EB = EngineBuilder(std::unique_ptr(mod)); + EB.setEngineKind(EngineKind::Kind::JIT); + EB.setUseMCJIT(true); + EB.setErrorStr(&comperr); + EB.setVerifyModules(true); + EB.setOptLevel(CodeGenOpt::Level::None); + + ExecutionEngine *EE = EB.create(); + if (!EE) { + fprintf(stderr, "Error: %s\n", errstr.c_str()); + exit(1); + } + + //mod->dump(); + //InspectPkt->dump(); + mod->getFunction("m_freem")->dump(); + + printf("FuncPtr: %p\n", (void *)EE->getPointerToFunction(Func)); + //printf("FuncPtr: %p\n", (void *)EE->getFunctionAddress("ipfw_chk_jit")); + err(1,"null"); + return (funcptr)EE->getFunctionAddress("ipfw_chk_jit"); + } + + void + end_rule() + { + rulenumber++; + } + void emit_outer_for_prologue() { @@ -528,7 +631,9 @@ // continue; // skip_or = 0; - Irb.SetInsertPoint(Outer_for_prologue); + // Write at the rule. + Irb.SetInsertPoint(rules[rulenumber]); + // uInt32_t tablearg = 0; Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Tablearg); @@ -557,8 +662,6 @@ // skip_or = 0; Irb.SetInsertPoint(jf); Irb.CreateStore(ConstantInt::get(Int32Ty, 0), SkipOr); - - Irb.CreateBr(Inner_for_prologue); } void @@ -583,7 +686,6 @@ // continue; // } // match = 0; /* set to 1 if we succeed */ - Irb.SetInsertPoint(Inner_for_prologue); // l = f->cmd_len; Value *FL = Irb.CreateLoad(F); @@ -632,10 +734,9 @@ Irb.SetInsertPoint(firstf); // match = 0; Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Match); - - Irb.CreateBr(Inner_for_epilogue); } + // We get here ar the end of switch() on opcodes. void emit_inner_for_epilogue() @@ -647,6 +748,7 @@ BasicBlock *matchzero = BasicBlock::Create(Con, "matchzero", Func); BasicBlock *matchnotzero = BasicBlock::Create(Con, "matchnotzero", Func); BasicBlock *is_or = BasicBlock::Create(Con, "is_or", Func); + BasicBlock *Continue = BasicBlock::Create(Con, "Continue", Func); Value *Comp, *AndOp; @@ -657,7 +759,7 @@ Value *Sub = Irb.CreateNSWSub(LL, CmdLenL); Irb.CreateStore(Sub, L); - // TODO -- Should ensure correctness of code. + // TODO - Should ensure correctness of code. // ipfw_insn *cmd; Add to pointer. // Note: Since LLVM can't add to a ptr, we can use GEP with casted Ptr. // cmd += cmdlen; @@ -676,8 +778,6 @@ // break; /* try next rule */ // } - Irb.SetInsertPoint(Inner_for_epilogue); - // if (cmd->len & F_NOT) Value *Len = Irb.CreateStructGEP(CmdL, 1); Value *LenL = Irb.CreateLoad(Len); @@ -702,6 +802,7 @@ Irb.SetInsertPoint(sec_cond); // if (match) + MatchL = Irb.CreateLoad(Match); Comp = Irb.CreateICmpNE(MatchL, ConstantInt::get(Int32Ty, 0)); Irb.CreateCondBr(Comp, matchnotzero, matchzero); @@ -709,28 +810,29 @@ // if (cmd->len & F_OR) AndOp = Irb.CreateAnd(LenL, ConstantInt::get(Int8Ty, F_OR)); Comp = Irb.CreateICmpNE(AndOp, ConstantInt::get(Int8Ty, 0)); - Irb.CreateCondBr(Comp, is_or, Outer_for_epilogue); + Irb.CreateCondBr(Comp, is_or, Continue); Irb.SetInsertPoint(is_or); // skip_or = 1; Irb.CreateStore(ConstantInt::get(Int32Ty, 1), SkipOr); - Irb.CreateBr(Outer_for_epilogue); + Irb.CreateBr(Continue); Irb.SetInsertPoint(matchzero); // if (!(cmd->len & F_OR)) /* not an OR block, */ // break; AndOp = Irb.CreateAnd(LenL, ConstantInt::get(Int8Ty, F_OR)); Comp = Irb.CreateICmpEQ(AndOp, ConstantInt::get(Int8Ty, 0)); - Irb.CreateCondBr(Comp, nextRule(rulenumber+1) /* break */, Outer_for_epilogue); + Irb.CreateCondBr(Comp, nextRule(rulenumber+1) /* break */, Continue); + + Irb.SetInsertPoint(Continue); } + // This code gets executed at the end of inner loop. // In this context, break means goto end, else continue loop. void emit_outer_for_epilogue() { - Irb.SetInsertPoint(Outer_for_epilogue); - // f_pos++, increment of the for loop. Value *FPosL = Irb.CreateLoad(FPos); Value *AddOp = Irb.CreateAdd(FPosL, ConstantInt::get(Int32Ty, 1)); @@ -743,6 +845,7 @@ Irb.CreateCondBr(Comp, End, nextRule(rulenumber+1)); } + void emit_end() { @@ -750,7 +853,11 @@ BasicBlock *Jt = BasicBlock::Create(Con, "jt", Func); BasicBlock *Jf = BasicBlock::Create(Con, "jf", Func); + BasicBlock *DoCache = BasicBlock::Create(Con, "cache", Func); BasicBlock *Ret = BasicBlock::Create(Con, "ret", Func); + #ifdef __FreeBSD__ + BasicBlock *CacheNN = BasicBlock::Create(Con, "cachennull", Func); + #endif Value *Comp, *AddOp; // if (done) { @@ -816,6 +923,7 @@ Value *TimeUptimeL32 = Irb.CreateTrunc(TimeUptimeL, Int32Ty); Value *Timestamp = Irb.CreateStructGEP(RuleL, 10); Irb.CreateStore(TimeUptimeL32, Timestamp); + Irb.CreateBr(DoCache); Irb.SetInsertPoint(Jf); // retval = IP_FW_DENY; @@ -823,166 +931,29 @@ Irb.CreateStore(ConstantInt::get(Int32Ty, IP_FW_DENY), Retval); Value *StrFirstElement = Irb.CreateStructGEP(Str, 0); Irb.CreateCall(PrintfFunc, StrFirstElement); + Irb.CreateBr(DoCache); + + Irb.SetInsertPoint(DoCache); #ifndef __FreeBSD__ - Irb.CreateBr(ret); + Irb.CreateBr(Ret); #endif #ifdef __FreeBSD__ - { - Irb.SetInsertPoint(End); - BasicBlock *CacheNN = BasicBlock::Create(Con, "cachennull", Func); - // if (ucred_cache != NULL) - Comp = Irb.CreateICmpNE(Ucred_cache, - ConstantPointerNull::get(UcredPtrTy)); - Irb.CreateCondBr(Comp, CacheNN, Ret); + // if (ucred_cache != NULL) + Comp = Irb.CreateICmpNE(Ucred_cache, + ConstantPointerNull::get(UcredPtrTy)); + Irb.CreateCondBr(Comp, CacheNN, Ret); - Irb.SetInsertPoint(CacheNN); - Irb.CreateBr(Ret); - } + Irb.SetInsertPoint(CacheNN); + Irb.CreateBr(Ret); #endif + //Return retval Irb.SetInsertPoint(Ret); - Irb.CreateRet(Retval); + Value *RetvalL = Irb.CreateLoad(Retval); + Irb.CreateRet(RetvalL); } - public: - ipfwJIT(int rulesnumber): Irb(Con) - { - // Create the module and load the code. - mod = loadBitcode("ip_fw_rules.bc"); - - Func = mod->getFunction("ipfw_chk_jit"); - Func->setLinkage(GlobalValue::ExternalLinkage); - - // Initialize the vector. - rules = std::vector(rulesnumber); - for (auto &i: rules){ - i = BasicBlock::Create(Con, "rule", Func); - } - - // Create static BasicBlocks. - // The entry basic block contains all the initialization - // and allocation of resources, and a basic check done - // before start emmiting the rules code. - Entry = BasicBlock::Create(Con, "Entry", Func); - End = BasicBlock::Create(Con, "End", Func); - Check_tag = BasicBlock::Create(Con, "CheckTag", Func); - // This is equivalent to the pullup_failed tag. - Pullup_failed = BasicBlock::Create(Con, "PullupFailed", Func); - //Snippets of code to be executed when iterating through the rules. - Outer_for_prologue = BasicBlock::Create(Con, "OuterForPrologue", Func); - Inner_for_prologue = BasicBlock::Create(Con, "InnerForPrologue", Func); - Inner_for_epilogue = BasicBlock::Create(Con, "InnerForEpilogue", Func); - Outer_for_epilogue = BasicBlock::Create(Con, "OuterForEpilogue", Func); - - // Get struct types, and store vars - setEnv(); - - // Start compilation - allocaAndInit(); - emit_check_tag(); - emit_pullup_failed(); - - // Snippets of code to be used for each iteration. - emit_outer_for_prologue(); - emit_inner_for_prologue(); - emit_inner_for_epilogue(); - emit_outer_for_epilogue(); - emit_end(); - } - ~ipfwJIT() - { - if (mod) - delete mod; - } - - funcptr - compile() - { - std::string errstr; - std::string comperr = "Compilation error\n"; - - // Check correctness. - verifyFunction(*Func); - verifyModule(*mod); - - InitializeNativeTarget(); - LLVMLinkInJIT(); - - //Optimise - PassManagerBuilder PMBuilder; - PMBuilder.OptLevel = 0; - PMBuilder.Inliner = createFunctionInliningPass(275); - - // Function passes - FunctionPassManager *PerFunctionPasses = new FunctionPassManager(mod); - PMBuilder.populateFunctionPassManager(*PerFunctionPasses); - PerFunctionPasses->run(*Func); - PerFunctionPasses->doFinalization(); - delete PerFunctionPasses; - - // Module passes - PassManager *PerModulePasses = new PassManager(); - PMBuilder.populateModulePassManager(*PerModulePasses); - //PerModulePasses->run(*mod); - delete PerModulePasses; - - // We don't need it anymore. - Function *vf = mod->getFunction("voidfunction"); - vf->eraseFromParent(); - - //Compile - EngineBuilder EB = EngineBuilder(std::unique_ptr(mod)); - EB.setErrorStr(&comperr); - - ExecutionEngine *EE = EB.create(); - if (!EE) { - fprintf(stderr, "Error: %s\n", errstr.c_str()); - exit(1); - } - - printf("FuncPtr: %p\n", (void *)EE->getFunctionAddress("ipfw_chk_jit")); - err(1,"null"); - return (funcptr)EE->getFunctionAddress("ipfw_chk_jit"); - } - - void - end_rule() - { - rulenumber++; - } - - // Also initialized the rules vector. - void - emit_outer_for_prologue_call() - { - Irb.SetInsertPoint(rules[rulenumber]); - Irb.CreateBr(Outer_for_prologue); - } - - void - emit_inner_for_prologue_call() - { - Irb.CreateBr(Inner_for_prologue); - } - - void - emit_inner_for_epilogue_call() - { - Irb.CreateBr(Inner_for_epilogue); - } - - void - emit_outer_for_epilogue_call() - { - Irb.CreateBr(Outer_for_epilogue); - } - - void - emit_end_call() - { - Irb.CreateBr(End); - } // Rules void @@ -1069,14 +1040,14 @@ f = chain->map[f_pos]; // Rule start. - compiler.emit_outer_for_prologue_call(); + compiler.emit_outer_for_prologue(); // For each different command. for (l = f->cmd_len, cmd = f->cmd ; l > 0 ; l -= cmdlen, cmd += cmdlen) { /* check_body: */ cmdlen = F_LEN(cmd); - compiler.emit_inner_for_prologue_call(); + compiler.emit_inner_for_prologue(); switch (cmd->opcode) { case O_NOP: compiler.emit_nop(); @@ -1458,14 +1429,14 @@ default: panic("-- unknown opcode %d\n", cmd->opcode); } /* end of switch() on opcodes */ - compiler.emit_inner_for_epilogue_call(); + compiler.emit_inner_for_epilogue(); } /* end of inner loop, scan opcodes */ // Rule ends. - compiler.emit_outer_for_epilogue_call(); + compiler.emit_outer_for_epilogue(); compiler.end_rule(); } /* end of outer for, scan rules */ - compiler.emit_end_call(); + compiler.emit_end(); // Once we're done iterating through the rules, return the pointer. return (compiler.compile()); From owner-svn-soc-all@FreeBSD.ORG Wed Sep 3 18:00:57 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id DA28C821 for ; Wed, 3 Sep 2014 18:00:57 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C63571DCD for ; Wed, 3 Sep 2014 18:00:57 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s83I0vuG088781 for ; Wed, 3 Sep 2014 18:00:57 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s83I0vpX088544 for svn-soc-all@FreeBSD.org; Wed, 3 Sep 2014 18:00:57 GMT (envelope-from dpl@FreeBSD.org) Date: Wed, 3 Sep 2014 18:00:57 GMT Message-Id: <201409031800.s83I0vpX088544@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r273569 - soc2014/dpl/netmap-ipfwjit/extra MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Sep 2014 18:00:57 -0000 Author: dpl Date: Wed Sep 3 18:00:56 2014 New Revision: 273569 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=273569 Log: Typo. Modified: soc2014/dpl/netmap-ipfwjit/extra/missing.c Modified: soc2014/dpl/netmap-ipfwjit/extra/missing.c ============================================================================== --- soc2014/dpl/netmap-ipfwjit/extra/missing.c Wed Sep 3 17:51:03 2014 (r273568) +++ soc2014/dpl/netmap-ipfwjit/extra/missing.c Wed Sep 3 18:00:56 2014 (r273569) @@ -36,7 +36,7 @@ /* - * Global bariables in the kernel + * Global variables in the kernel */ int ticks; /* kernel ticks counter */ int hz = 1000; /* default clock time */ From owner-svn-soc-all@FreeBSD.ORG Wed Sep 3 18:01:57 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7EC7783C for ; Wed, 3 Sep 2014 18:01:57 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6AFC71DDA for ; Wed, 3 Sep 2014 18:01:57 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s83I1vB4015048 for ; Wed, 3 Sep 2014 18:01:57 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s83I1uCJ014812 for svn-soc-all@FreeBSD.org; Wed, 3 Sep 2014 18:01:56 GMT (envelope-from dpl@FreeBSD.org) Date: Wed, 3 Sep 2014 18:01:56 GMT Message-Id: <201409031801.s83I1uCJ014812@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r273570 - soc2014/dpl/netmap-ipfwjit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Sep 2014 18:01:57 -0000 Author: dpl Date: Wed Sep 3 18:01:56 2014 New Revision: 273570 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=273570 Log: Changed bitcode's name Modified: soc2014/dpl/netmap-ipfwjit/Makefile.kipfw Modified: soc2014/dpl/netmap-ipfwjit/Makefile.kipfw ============================================================================== --- soc2014/dpl/netmap-ipfwjit/Makefile.kipfw Wed Sep 3 18:00:56 2014 (r273569) +++ soc2014/dpl/netmap-ipfwjit/Makefile.kipfw Wed Sep 3 18:01:56 2014 (r273570) @@ -153,8 +153,8 @@ ip_fw2.o: jit.o #Generate the actual bytecode to be used -../ip_fw_rules.bc: - $(HIDE) $(CC) $(CFLAGS) -emit-llvm -c -o ../ip_fw_rules.bc ../sys/netpfil/ipfw/ip_fw_rules.c +../rules.bc: + $(HIDE) $(CC) $(CFLAGS) -emit-llvm -c -o ../rules.bc ../sys/netpfil/ipfw/ip_fw_rules.c radix.o:# CFLAGS += -U_KERNEL @@ -165,7 +165,7 @@ $(MSG) " LD $@" $(HIDE) clang++ -Wl,--start-group $(LIBS) $^ -Wl,--end-group -o $@ -jit.o: jit.cc ../ip_fw_rules.bc +jit.o: jit.cc ../rules.bc $(MSG) " CC $<" $(HIDE)@clang++ -c $(J_CFLAGS) `llvm-config-devel --cxxflags` -g -O0 -o ./jit.o ../sys/netpfil/ipfw/jit.cc clean: From owner-svn-soc-all@FreeBSD.ORG Wed Sep 3 18:03:35 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C1F4A862 for ; Wed, 3 Sep 2014 18:03:35 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id ADC581DE6 for ; Wed, 3 Sep 2014 18:03:35 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s83I3Zru051098 for ; Wed, 3 Sep 2014 18:03:35 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s83I3ZV0050971 for svn-soc-all@FreeBSD.org; Wed, 3 Sep 2014 18:03:35 GMT (envelope-from dpl@FreeBSD.org) Date: Wed, 3 Sep 2014 18:03:35 GMT Message-Id: <201409031803.s83I3ZV0050971@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r273571 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Sep 2014 18:03:35 -0000 Author: dpl Date: Wed Sep 3 18:03:34 2014 New Revision: 273571 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=273571 Log: Added the needed stuff to have a complete bitcode. Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.c Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.c ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.c Wed Sep 3 18:01:56 2014 (r273570) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.c Wed Sep 3 18:03:34 2014 (r273571) @@ -1,5 +1,6 @@ #include #include + #include #define IPFW_RULES_INLINE __unused #include "ip_fw_rules.h" @@ -7,6 +8,71 @@ // The real function will be compiled and inserted by the JIT. int ipfw_chk_jit(struct ip_fw_args *args, struct ip_fw_chain *chain); +void crfree(struct ucred *); +time_t time_uptime = 0; + +/* XXX Function defined at ip_fw_sockopt.c + * Find the smallest rule >= key, id. + * We could use bsearch but it is so simple that we code it directly + */ +int +ipfw_find_rule(struct ip_fw_chain *chain, uint32_t key, uint32_t id) +{ + int i, lo, hi; + struct ip_fw *r; + + for (lo = 0, hi = chain->n_rules - 1; lo < hi;) { + i = (lo + hi) / 2; + r = chain->map[i]; + if (r->rulenum < key) + lo = i + 1; /* continue from the next one */ + else if (r->rulenum > key) + hi = i; /* this might be good */ + else if (r->id < id) + lo = i + 1; /* continue from the next one */ + else /* r->id >= id */ + hi = i; /* this might be good */ + }; + return hi; +} + +/* Defined at extra/missing.c */ +struct tags_freelist tags_freelist; +int tags_minlen = 64; +int tags_freelist_count = 0; +static int tags_freelist_max = 0; + +struct mbuf *mbuf_freelist; + +void +m_freem(struct mbuf *m) +{ + struct m_tag *t; + + /* free the m_tag chain */ + while ( (t = SLIST_FIRST(&m->m_pkthdr.tags) ) ) { + ND("free tag %p", &m->m_pkthdr.tags); + SLIST_REMOVE_HEAD(&m->m_pkthdr.tags, m_tag_link); + SLIST_INSERT_HEAD(&tags_freelist, t, m_tag_link); + tags_freelist_count++; + if (tags_freelist_count > tags_freelist_max) { + static int pr=0; + if ((pr++ % 1000) == 0) + D("new max %d", tags_freelist_count); + tags_freelist_max = tags_freelist_count; + } + } + if (m->m_flags & M_STACK) { + ND("free invalid mbuf %p", m); + return; + } + /* free the mbuf */ + ND("free(m = %p, M_IPFW);", m); + m->m_next = mbuf_freelist; + mbuf_freelist = m; +}; + + // Declarations of some needed structs. struct mbuf; struct ifnet; @@ -26,14 +92,6 @@ struct ucred; #endif -// Functions used by JIT, external. -int printf(const char * restrict format, ...); -int ipfw_find_rule(struct ip_fw_chain *chain, uint32_t key, uint32_t id); -void crfree(struct ucred *); - -// As done at netmap-ipfw -time_t time_uptime = 0; - // This functions only forces the compiler to store the stubs of the functions // so that they can be used by the JIT-compiled code instead. // this functions is not to be called anywhere. @@ -42,6 +100,7 @@ { struct ip_fw_args arguments; struct ip_fw_chain chainss; + uint32_t thing; #ifndef __FreeBSD__ struct bsd_ucred user_creds; @@ -68,5 +127,8 @@ crfree(ucreds); #endif + + thing = htonl(thing); + thing = ntohl(thing); } From owner-svn-soc-all@FreeBSD.ORG Wed Sep 3 18:04:12 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 5668887B for ; Wed, 3 Sep 2014 18:04:12 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 428671DEA for ; Wed, 3 Sep 2014 18:04:12 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s83I4Cdl059458 for ; Wed, 3 Sep 2014 18:04:12 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s83I4BjH059258 for svn-soc-all@FreeBSD.org; Wed, 3 Sep 2014 18:04:11 GMT (envelope-from dpl@FreeBSD.org) Date: Wed, 3 Sep 2014 18:04:11 GMT Message-Id: <201409031804.s83I4BjH059258@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r273572 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Sep 2014 18:04:12 -0000 Author: dpl Date: Wed Sep 3 18:04:11 2014 New Revision: 273572 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=273572 Log: Removed unneded declarations. Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Wed Sep 3 18:03:34 2014 (r273571) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Wed Sep 3 18:04:11 2014 (r273572) @@ -35,9 +35,6 @@ #include /* XXX for in_cksum */ -// The real function will be compiled and inserted by the JIT. -int ipfw_chk_jit(struct ip_fw_args *args, struct ip_fw_chain *chain); - // Declarations of some needed structs. struct mbuf; @@ -57,10 +54,6 @@ struct ucred; #endif -// Functions used by JIT, external. -int printf(const char * restrict format, ...); -int ipfw_find_rule(struct ip_fw_chain *chain, uint32_t key, uint32_t id); - VNET_DEFINE(int, fw_verbose); VNET_DEFINE(u_int32_t, set_disable); From owner-svn-soc-all@FreeBSD.ORG Wed Sep 3 18:05:05 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 57167899 for ; Wed, 3 Sep 2014 18:05:05 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 428A91DF1 for ; Wed, 3 Sep 2014 18:05:05 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s83I55v5072455 for ; Wed, 3 Sep 2014 18:05:05 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s83I54su072326 for svn-soc-all@FreeBSD.org; Wed, 3 Sep 2014 18:05:04 GMT (envelope-from dpl@FreeBSD.org) Date: Wed, 3 Sep 2014 18:05:04 GMT Message-Id: <201409031805.s83I54su072326@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r273573 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Sep 2014 18:05:05 -0000 Author: dpl Date: Wed Sep 3 18:05:04 2014 New Revision: 273573 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=273573 Log: Now deletion of the ipfwJIT object is safe for compiled code. Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Wed Sep 3 18:04:11 2014 (r273572) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Wed Sep 3 18:05:04 2014 (r273573) @@ -47,7 +47,7 @@ class ipfwJIT { Module *mod; Function *Func; - LLVMContext Con; + LLVMContext *Con; IRBuilder<> Irb; // We'll store the BasicBlock objects for each rule here. @@ -175,7 +175,7 @@ return (NULL); } - auto modptr = parseBitcodeFile(buff.get().get(), Con); + auto modptr = parseBitcodeFile(buff.get().get(), *Con); if ((modptr.getError())){ std::cerr << "Failed to parse bitcode: " << buff.getError() << "\n"; return (NULL); @@ -208,10 +208,10 @@ Chain = &arglist.back(); // Get Type objects - Int8Ty = Type::getInt8Ty(Con); - Int16Ty = Type::getInt16Ty(Con); - Int32Ty = Type::getInt32Ty(Con); - Int64Ty = Type::getInt64Ty(Con); + Int8Ty = Type::getInt8Ty(*Con); + Int16Ty = Type::getInt16Ty(*Con); + Int32Ty = Type::getInt32Ty(*Con); + Int64Ty = Type::getInt64Ty(*Con); Int8PtrTy = PointerType::getUnqual(Int8Ty); // Get StrucType from bitcode. @@ -401,8 +401,8 @@ void emit_pullup_failed() { - BasicBlock *print = BasicBlock::Create(Con, "print", Func); - BasicBlock *ret = BasicBlock::Create(Con, "ret", Func); + BasicBlock *print = BasicBlock::Create(*Con, "print", Func); + BasicBlock *ret = BasicBlock::Create(*Con, "ret", Func); Value *Is_verbose, *Str, *Comp; @@ -440,10 +440,10 @@ void emit_check_tag() { - BasicBlock *Tagged = BasicBlock::Create(Con, "tagged", Func); - BasicBlock *Nottagged = BasicBlock::Create(Con, "nottagged", Func); - BasicBlock *Jt = BasicBlock::Create(Con, "jt", Func); - BasicBlock *Jf = BasicBlock::Create(Con, "jf", Func); + BasicBlock *Tagged = BasicBlock::Create(*Con, "tagged", Func); + BasicBlock *Nottagged = BasicBlock::Create(*Con, "nottagged", Func); + BasicBlock *Jt = BasicBlock::Create(*Con, "jt", Func); + BasicBlock *Jf = BasicBlock::Create(*Con, "jf", Func); Value *Comp; @@ -509,7 +509,7 @@ } public: - ipfwJIT(int rulesnumber): Irb(Con) + ipfwJIT(int rulesnumber) : Con(&getGlobalContext()), Irb(*Con) { // Create the module and load the code. mod = loadBitcode("rules.bc"); @@ -520,10 +520,10 @@ // The entry basic block contains all the initialization // and allocation of resources, and a basic check done // before start emmiting the rules code. - Entry = BasicBlock::Create(Con, "Entry", Func); - End = BasicBlock::Create(Con, "End", Func); - CheckTag = BasicBlock::Create(Con, "CheckTag", Func); - PullupFailed = BasicBlock::Create(Con, "PullupFailed", Func); + Entry = BasicBlock::Create(*Con, "Entry", Func); + End = BasicBlock::Create(*Con, "End", Func); + CheckTag = BasicBlock::Create(*Con, "CheckTag", Func); + PullupFailed = BasicBlock::Create(*Con, "PullupFailed", Func); // Get struct types, and store vars @@ -535,17 +535,12 @@ // Initialize the vector. rules = std::vector(rulesnumber); for (auto &i: rules){ - i = BasicBlock::Create(Con, "rule", Func); + i = BasicBlock::Create(*Con, "rule", Func); } emit_check_tag(); emit_pullup_failed(); } - ~ipfwJIT() - { - if (mod) - delete mod; - } funcptr compile() @@ -553,58 +548,49 @@ InitializeNativeTarget(); LLVMLinkInJIT(); -// //Optimise -// PassManagerBuilder PMBuilder; -// PMBuilder.OptLevel = 1; -// PMBuilder.Inliner = createFunctionInliningPass(275); - -// // Function passes -// FunctionPassManager *PerFunctionPasses = new FunctionPassManager(mod); -// PMBuilder.populateFunctionPassManager(*PerFunctionPasses); -// PerFunctionPasses->run(*Func); -// PerFunctionPasses->doFinalization(); -// delete PerFunctionPasses; - -// printf("Done optimizing Function\n"); - -// // Module passes -// PassManager *PerModulePasses = new PassManager(); -// PMBuilder.populateModulePassManager(*PerModulePasses); -// PerModulePasses->run(*mod); -// delete PerModulePasses; - -// printf("Done optimizing Module\n"); - - // // We don't need it anymore. - // Function *vf = mod->getFunction("voidfunction"); - // vf->eraseFromParent(); - // printf("Done erasing voidfunction\n"); + // Optimise + PassManagerBuilder PMBuilder; + PMBuilder.OptLevel = 3; + PMBuilder.Inliner = createFunctionInliningPass(275); + + // Function passes + FunctionPassManager *PerFunctionPasses = new FunctionPassManager(mod); + PMBuilder.populateFunctionPassManager(*PerFunctionPasses); + PerFunctionPasses->run(*Func); + PerFunctionPasses->doFinalization(); + delete PerFunctionPasses; + + // Module passes + PassManager *PerModulePasses = new PassManager(); + PMBuilder.populateModulePassManager(*PerModulePasses); + PerModulePasses->run(*mod); + delete PerModulePasses; + + // We don't need it anymore. + Function *vf = mod->getFunction("voidfunction"); + vf->eraseFromParent(); //Compile - std::string comperr = "Compilation error\n"; std::string errstr; EngineBuilder EB = EngineBuilder(std::unique_ptr(mod)); EB.setEngineKind(EngineKind::Kind::JIT); + EB.setErrorStr(&errstr); + EB.setOptLevel(CodeGenOpt::Level::Aggressive); EB.setUseMCJIT(true); - EB.setErrorStr(&comperr); EB.setVerifyModules(true); - EB.setOptLevel(CodeGenOpt::Level::None); ExecutionEngine *EE = EB.create(); if (!EE) { - fprintf(stderr, "Error: %s\n", errstr.c_str()); + fprintf(stderr, "Compilation error: %s\n", errstr.c_str()); exit(1); } - //mod->dump(); - //InspectPkt->dump(); - mod->getFunction("m_freem")->dump(); - - printf("FuncPtr: %p\n", (void *)EE->getPointerToFunction(Func)); - //printf("FuncPtr: %p\n", (void *)EE->getFunctionAddress("ipfw_chk_jit")); - err(1,"null"); - return (funcptr)EE->getFunctionAddress("ipfw_chk_jit"); + // printf("FuncPtr: %p\n", (void *)EE->getPointerToFunction(Func)); + // printf("FuncPtr: %p\n", (void *)EE->getPointerToNamedFunction("ipfw_chk_jit")); + // printf("FuncPtr: %p\n", (void *)EE->getFunctionAddress("ipfw_chk_jit")); + // return (funcptr)EE->getFunctionAddress("ipfw_chk_jit"); + return (funcptr)EE->getPointerToFunction(mod->getFunction("ipfw_chk_jit")); } void @@ -616,8 +602,8 @@ void emit_outer_for_prologue() { - BasicBlock *jt = BasicBlock::Create(Con, "jt", Func); - BasicBlock *jf = BasicBlock::Create(Con, "jf", Func); + BasicBlock *jt = BasicBlock::Create(*Con, "jt", Func); + BasicBlock *jf = BasicBlock::Create(*Con, "jf", Func); Value *SetDisable = mod->getGlobalVariable("set_disable"); @@ -667,10 +653,10 @@ void emit_inner_for_prologue() { - BasicBlock *firstt = BasicBlock::Create(Con, "firstt", Func); - BasicBlock *firstf = BasicBlock::Create(Con, "firstf", Func); - BasicBlock *secondt = BasicBlock::Create(Con, "secondt", Func); - BasicBlock *secondf = BasicBlock::Create(Con, "secondf", Func); + BasicBlock *firstt = BasicBlock::Create(*Con, "firstt", Func); + BasicBlock *firstf = BasicBlock::Create(*Con, "firstf", Func); + BasicBlock *secondt = BasicBlock::Create(*Con, "secondt", Func); + BasicBlock *secondf = BasicBlock::Create(*Con, "secondf", Func); Value *Comp, *AndOp; @@ -741,14 +727,14 @@ void emit_inner_for_epilogue() { - BasicBlock *matchnz = BasicBlock::Create(Con, "matchnz", Func); - BasicBlock *matchz = BasicBlock::Create(Con, "matchz", Func); - BasicBlock *jt = BasicBlock::Create(Con, "jt", Func); - BasicBlock *sec_cond = BasicBlock::Create(Con, "sec_cond", Func); - BasicBlock *matchzero = BasicBlock::Create(Con, "matchzero", Func); - BasicBlock *matchnotzero = BasicBlock::Create(Con, "matchnotzero", Func); - BasicBlock *is_or = BasicBlock::Create(Con, "is_or", Func); - BasicBlock *Continue = BasicBlock::Create(Con, "Continue", Func); + BasicBlock *matchnz = BasicBlock::Create(*Con, "matchnz", Func); + BasicBlock *matchz = BasicBlock::Create(*Con, "matchz", Func); + BasicBlock *jt = BasicBlock::Create(*Con, "jt", Func); + BasicBlock *sec_cond = BasicBlock::Create(*Con, "sec_cond", Func); + BasicBlock *matchzero = BasicBlock::Create(*Con, "matchzero", Func); + BasicBlock *matchnotzero = BasicBlock::Create(*Con, "matchnotzero", Func); + BasicBlock *is_or = BasicBlock::Create(*Con, "is_or", Func); + BasicBlock *Continue = BasicBlock::Create(*Con, "Continue", Func); Value *Comp, *AndOp; @@ -851,12 +837,12 @@ { Value *Rule, *TimeUptime, *Str; - BasicBlock *Jt = BasicBlock::Create(Con, "jt", Func); - BasicBlock *Jf = BasicBlock::Create(Con, "jf", Func); - BasicBlock *DoCache = BasicBlock::Create(Con, "cache", Func); - BasicBlock *Ret = BasicBlock::Create(Con, "ret", Func); + BasicBlock *Jt = BasicBlock::Create(*Con, "jt", Func); + BasicBlock *Jf = BasicBlock::Create(*Con, "jf", Func); + BasicBlock *DoCache = BasicBlock::Create(*Con, "cache", Func); + BasicBlock *Ret = BasicBlock::Create(*Con, "ret", Func); #ifdef __FreeBSD__ - BasicBlock *CacheNN = BasicBlock::Create(Con, "cachennull", Func); + BasicBlock *CacheNN = BasicBlock::Create(*Con, "cachennull", Func); #endif Value *Comp, *AddOp; @@ -1019,9 +1005,6 @@ int res; int f_pos = 0; - InitializeNativeTarget(); - LLVMLinkInJIT(); - if (chain->n_rules == 0) return (NULL); From owner-svn-soc-all@FreeBSD.ORG Thu Sep 4 12:25:33 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9B3A7C0C for ; Thu, 4 Sep 2014 12:25:33 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 85A5B1EFD for ; Thu, 4 Sep 2014 12:25:33 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s84CPXUb041879 for ; Thu, 4 Sep 2014 12:25:33 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s84CPXoD041838 for svn-soc-all@FreeBSD.org; Thu, 4 Sep 2014 12:25:33 GMT (envelope-from dpl@FreeBSD.org) Date: Thu, 4 Sep 2014 12:25:33 GMT Message-Id: <201409041225.s84CPXoD041838@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r273620 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Sep 2014 12:25:33 -0000 Author: dpl Date: Thu Sep 4 12:25:32 2014 New Revision: 273620 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=273620 Log: Added boilerplate for code generation. Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Thu Sep 4 11:15:38 2014 (r273619) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Thu Sep 4 12:25:32 2014 (r273620) @@ -184,12 +184,13 @@ } BasicBlock* - nextRule(int num) + nextRule() { - if (num >= rules.size()) + int nextn = rulenumber+1; + if (nextn >= rules.size()) return (End); else - return (rules[num]); + return (rules[nextn]); } // Create the needed variables to perform pkt filtering. @@ -393,8 +394,8 @@ Dst_ip, Src_port, Dst_port, Etype, Ext_hd, Iplen, Pktlen, Is_ipv4, Is_ipv6, Hlen, Proto, Icmp6_type, Ip6f_mf, Offset, UlpL}); - Value *Cond = Irb.CreateICmpEQ(InspectPktCall, ConstantInt::get(Int32Ty, 1)); - Irb.CreateCondBr(Cond, PullupFailed, CheckTag); + Value *Comp = Irb.CreateICmpEQ(InspectPktCall, ConstantInt::get(Int32Ty, 1)); + Irb.CreateCondBr(Comp, PullupFailed, CheckTag); } // This is equivalent to the pullup_failed tag. @@ -643,7 +644,7 @@ Irb.SetInsertPoint(jt); // continue; - Irb.CreateBr(nextRule(rulenumber+1)); + Irb.CreateBr(nextRule()); // skip_or = 0; Irb.SetInsertPoint(jf); @@ -715,7 +716,7 @@ Irb.SetInsertPoint(secondf); // continue; - Irb.CreateBr(nextRule(rulenumber+1)); + Irb.CreateBr(nextRule()); Irb.SetInsertPoint(firstf); // match = 0; @@ -808,7 +809,7 @@ // break; AndOp = Irb.CreateAnd(LenL, ConstantInt::get(Int8Ty, F_OR)); Comp = Irb.CreateICmpEQ(AndOp, ConstantInt::get(Int8Ty, 0)); - Irb.CreateCondBr(Comp, nextRule(rulenumber+1) /* break */, Continue); + Irb.CreateCondBr(Comp, nextRule() /* break */, Continue); Irb.SetInsertPoint(Continue); } @@ -828,7 +829,7 @@ // break; Value *DoneL = Irb.CreateLoad(Done); Value *Comp = Irb.CreateICmpNE(DoneL, ConstantInt::get(Int32Ty, 0)); - Irb.CreateCondBr(Comp, End, nextRule(rulenumber+1)); + Irb.CreateCondBr(Comp, End, nextRule()); } @@ -945,6 +946,8 @@ void emit_nop() { + //break; + Irb.CreateBr(nextRule()); Irb.CreateStore(ConstantInt::get(Int32Ty, 1), Match); } @@ -954,29 +957,54 @@ printf("Compilation error:\n"); printf("ipfwjitter: opcode %d unimplemented\n", opcode); printf("Compilation continues.\n"); + //break; + Irb.CreateBr(nextRule()); } // check_uidgid() returns 0 on userspace. void emit_jail() { - // /* - // * We only check offset == 0 && proto != 0, - // * as this ensures that we have a - // * packet with the ports info. - // */ + BasicBlock *OffsetNZ = BasicBlock::Create(*Con, "offsetnotzero", Func); + BasicBlock *OffsetZE = BasicBlock::Create(*Con, "offsetiszero", Func); + BasicBlock *TCPorUDP = BasicBlock::Create(*Con, "setmatchzero", Func); + BasicBlock *Continue = BasicBlock::Create(*Con, "Continue", Func); + Value *Comp; + // if (offset != 0) - // return; + // break; // if (proto == IPPROTO_TCP || // proto == IPPROTO_UDP) // *match = 0; // if (offset != 0) - // return; + // break; + Value *OffsetL = Irb.CreateLoad(Offset); + Comp = Irb.CreateICmpNE(OffsetL, ConstantInt::get(Int16Ty, 0)); + Irb.CreateCondBr(Comp, OffsetNZ, OffsetZE); + + Irb.SetInsertPoint(OffsetNZ); + // Go to next rule. + Irb.CreateBr(nextRule()); // if (proto == IPPROTO_TCP || // proto == IPPROTO_UDP) // *match = 0; + Irb.SetInsertPoint(OffsetZE); + Value *ProtoL = Irb.CreateLoad(Proto); + Comp = Irb.CreateICmpEQ(OffsetL, ConstantInt::get(Int8Ty, IPPROTO_TCP)); + Value *Comp2 = Irb.CreateICmpEQ(OffsetL, ConstantInt::get(Int8Ty, IPPROTO_UDP)); + Irb.CreateCondBr(Comp, TCPorUDP, Continue); + Irb.CreateCondBr(Comp2, TCPorUDP, Continue); + + Irb.SetInsertPoint(TCPorUDP); + Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Match); + Irb.CreateBr(Continue); + + // Keep on with the for epilogue. + Irb.SetInsertPoint(Continue); + //break; + Irb.CreateBr(nextRule()); } void @@ -987,6 +1015,8 @@ Value *cmdc = Irb.CreateBitCast(Cmd, Ipfw_insn_ifPtrTy); Value *IfaceMatchCall = Irb.CreateCall4(Iface_match, rcvif, cmdc, Chain, Tablearg); Irb.CreateStore(IfaceMatchCall, Match); + //break; + Irb.CreateBr(nextRule()); } void @@ -996,6 +1026,602 @@ Value *Cmdc = Irb.CreateBitCast(Cmd, Ipfw_insn_ifPtrTy); Value *IfaceMatchCall = Irb.CreateCall4(Iface_match, Oif, Cmdc, Chain, Tablearg); Irb.CreateStore(IfaceMatchCall, Match); + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_via() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_macaddr2() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_mac_type() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_frag() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_in() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_layer2() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_diverted() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_proto() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_ip_src() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_ip_dst_lookup() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_ip_dst_mask() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_ip_src_me() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_ip6_src_me() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_ip_src_set() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_ip_dst() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_ip_dst_me() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_ip6_dst_me() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_ip_dstport() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_icmptype() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_icmp6type() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_ipopt() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_ipver() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_ipttl() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_ipprecedence() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_iptos() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_dscp() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_tcpdatalen() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_tcpflags() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_tcpopts() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_tcpseq() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_tcpack() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_tcpwin() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_estab() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_altq() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_log() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_prob() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_verrevpath() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_versrcreach() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_antispoof() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_ipsec() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_ip6_src() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_ip6_dst() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_ip6_dst_mask() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_flow6id() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_ext_hdr() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_ip6() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_ip4() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_tag() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_fib() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_sockarg() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_tagged() + { + + //break; + Irb.CreateBr(nextRule()); + } + + /* + * The second set of opcodes represents 'actions', + * i.e. the terminal part of a rule once the packet + * matches all previous patterns. + * Typically there is only one action for each rule, + * and the opcode is stored at the end of the rule + * (but there are exceptions -- see below). + * + * In general, here we set retval and terminate the + * outer loop (would be a 'break 3' in some language, + * but we need to set l=0, done=1) + * + * Exceptions: + * O_COUNT and O_SKIPTO actions: + * instead of terminating, we jump to the next rule + * (setting l=0), or to the SKIPTO target (setting + * f/f_len, cmd and l as needed), respectively. + * + * O_TAG, O_LOG and O_ALTQ action parameters: + * perform some action and set match = 1; + * + * O_LIMIT and O_KEEP_STATE: these opcodes are + * not real 'actions', and are stored right + * before the 'action' part of the rule. + * These opcodes try to install an entry in the + * state tables; if successful, we continue with + * the next opcode (match=1; break;), otherwise + * the packet must be dropped (set retval, + * break loops with l=0, done=1) + * + * O_PROBE_STATE and O_CHECK_STATE: these opcodes + * cause a lookup of the state table, and a jump + * to the 'action' part of the parent rule + * if an entry is found, or + * (CHECK_STATE only) a jump to the next rule if + * the entry is not found. + * The result of the lookup is cached so that + * further instances of these opcodes become NOPs. + * The jump to the next rule is done by setting + * l=0, cmdlen=0. + */ + + void + emit_keep_state() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_check_state() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_accept() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_queue() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_tee() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_count() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_skipto() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_callreturn() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_reject() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_unreach6() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_deny() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_forward_ip() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_forward_ip6() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_ngtee() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_setfib() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_setdscp() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_nat() + { + + //break; + Irb.CreateBr(nextRule()); + } + + void + emit_reass() + { + + //break; + Irb.CreateBr(nextRule()); } }; @@ -1054,7 +1680,6 @@ compiler.emit_xmit(); break; -/* XXX case O_VIA: compiler.emit_via(); break; @@ -1105,7 +1730,6 @@ compiler.emit_ip_src_me(); #ifdef INET6 /* FALLTHROUGH */ -/* XXX case O_IP6_SRC_ME: compiler.emit_ip6_src_me(); #endif @@ -1125,7 +1749,6 @@ #ifdef INET6 /* FALLTHROUGH */ -/* XXX case O_IP6_DST_ME: compiler.emit_ip6_dst_me(); #endif @@ -1146,7 +1769,6 @@ compiler.emit_icmp6type(); break; #endif /* INET6 */ -/* case O_IPOPT: compiler.emit_ipopt(); break; @@ -1230,7 +1852,6 @@ compiler.emit_ipsec(); #endif /* otherwise no match */ -/* XXX break; #ifdef INET6 @@ -1269,7 +1890,6 @@ break; case O_FIB: /* try match the specified fib */ -/* XXX compiler.emit_fib(); break; @@ -1322,7 +1942,6 @@ * The jump to the next rule is done by setting * l=0, cmdlen=0. */ -/* XXX case O_LIMIT: case O_KEEP_STATE: compiler.emit_keep_state(); @@ -1356,22 +1975,18 @@ continue; break; /* NOTREACHED */ -/* XXX case O_CALLRETURN: compiler.emit_callreturn(); continue; break; /* NOTREACHED */ -/* XXX case O_REJECT: compiler.emit_reject(); /* FALLTHROUGH */ -/* XXX #ifdef INET6 case O_UNREACH6: compiler.emit_unreach6(); /* FALLTHROUGH */ -/* XXX #endif case O_DENY: compiler.emit_deny(); @@ -1408,7 +2023,6 @@ compiler.emit_reass(); break; - */ default: panic("-- unknown opcode %d\n", cmd->opcode); } /* end of switch() on opcodes */ From owner-svn-soc-all@FreeBSD.ORG Fri Sep 5 11:18:11 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2BB8CEEC for ; Fri, 5 Sep 2014 11:18:11 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1746114A4 for ; Fri, 5 Sep 2014 11:18:11 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s85BIAJQ073069 for ; Fri, 5 Sep 2014 11:18:10 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s85BIAw7073065 for svn-soc-all@FreeBSD.org; Fri, 5 Sep 2014 11:18:10 GMT (envelope-from dpl@FreeBSD.org) Date: Fri, 5 Sep 2014 11:18:10 GMT Message-Id: <201409051118.s85BIAw7073065@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r273685 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Sep 2014 11:18:11 -0000 Author: dpl Date: Fri Sep 5 11:18:09 2014 New Revision: 273685 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=273685 Log: Moved JIT compilation to the ipfw_chk handler. Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_pfil.c Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c Fri Sep 5 07:42:34 2014 (r273684) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c Fri Sep 5 11:18:09 2014 (r273685) @@ -124,12 +124,6 @@ /* Use 128 tables by default */ static unsigned int default_fw_tables = IPFW_TABLES_DEFAULT; -/* JIT compiling API */ -funcptr compile_code(struct ip_fw_args *, struct ip_fw_chain *); - -/* Pointer to the actual compiled code */ -int (*compiledfuncptr)(struct ip_fw_args *, struct ip_fw_chain *) = 0; - /* * Each rule belongs to one of 32 different sets (0..31). * The variable set_disable contains one bit per set. @@ -271,19 +265,6 @@ args->f_id.fib = M_GETFIB(m); /* note mbuf not altered) */ - - /* If we haven't, JIT-compile the actions to be executed per-rule */ - if (compiledfuncptr == 0) { - IPFW_PF_RLOCK(chain); - if (! V_ipfw_vnet_ready) { /* shutting down, leave NOW. */ - IPFW_PF_RUNLOCK(chain); - return (IP_FW_PASS); /* accept */ - } - compiledfuncptr = compile_code(args, chain); - IPFW_PF_RUNLOCK(chain); - } else - return compiledfuncptr(args, chain); - /* * Local variables holding state while processing a packet: * Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_pfil.c ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_pfil.c Fri Sep 5 07:42:34 2014 (r273684) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_pfil.c Fri Sep 5 11:18:09 2014 (r273685) @@ -87,8 +87,19 @@ int ipfw_check_frame(void *, struct mbuf **, struct ifnet *, int, struct inpcb *); -#ifdef SYSCTL_NODE +/* JIT compilation */ +typedef int (*funcptr)(); +funcptr compile_code(struct ip_fw_args *, struct ip_fw_chain *); +/* Pointer to the actual compiled code */ +int (*compiledfuncptr)(struct ip_fw_args *, struct ip_fw_chain *) = 0; +struct ip_fw_chain *chain = &V_layer3_chain; + +/* ipfw_vnet_ready controls when we are open for business */ +VNET_DEFINE(int, ipfw_vnet_ready); +#define V_ipfw_vnet_ready VNET(ipfw_vnet_ready) + +#ifdef SYSCTL_NODE SYSBEGIN(f1) SYSCTL_DECL(_net_inet_ip_fw); @@ -108,10 +119,38 @@ ipfw_chg_hook, "I", "Pass ether pkts through firewall"); SYSEND - #endif /* SYSCTL_NODE */ /* + * Handles the compilation and execution of the + * JIT compiled code. + * + * dpl TODO: Threaded compilation. + */ +int +ipfw_chk_wrapper(struct ip_fw_args *args) +{ + int ret; + + /* If we haven't, JIT-compile the actions to be executed per-rule */ + if (compiledfuncptr == 0) { + IPFW_PF_RLOCK(chain); + if (! V_ipfw_vnet_ready) { /* shutting down, leave NOW. */ + IPFW_PF_RUNLOCK(chain); + return (IP_FW_PASS); /* accept */ + } + compiledfuncptr = compile_code(args, chain); + ret = compiledfuncptr(args, chain); + IPFW_PF_RUNLOCK(chain); + } else { + IPFW_PF_RLOCK(chain); + ret = compiledfuncptr(args, chain); + IPFW_PF_RUNLOCK(chain); + } + return (ret); +} + +/* * The pfilter hook to pass packets to ipfw_chk and then to * dummynet, divert, netgraph or other modules. * The packet may be consumed. @@ -146,7 +185,7 @@ args.oif = dir == DIR_OUT ? ifp : NULL; args.inp = inp; - ipfw = ipfw_chk(&args); + ipfw = ipfw_chk_wrapper(&args); *m0 = args.m; KASSERT(*m0 != NULL || ipfw == IP_FW_DENY, ("%s: m0 is NULL", @@ -339,7 +378,7 @@ args.next_hop6 = NULL; /* we do not support forward yet */ args.eh = &save_eh; /* MAC header for bridged/MAC packets */ args.inp = NULL; /* used by ipfw uid/gid/jail rules */ - i = ipfw_chk(&args); + i = ipfw_chk_wrapper(&args); m = args.m; if (m != NULL) { /* From owner-svn-soc-all@FreeBSD.ORG Fri Sep 5 11:24:18 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 877C817B for ; Fri, 5 Sep 2014 11:24:18 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7339E15A7 for ; Fri, 5 Sep 2014 11:24:18 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s85BOIJs080489 for ; Fri, 5 Sep 2014 11:24:18 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s85BOIdF080487 for svn-soc-all@FreeBSD.org; Fri, 5 Sep 2014 11:24:18 GMT (envelope-from dpl@FreeBSD.org) Date: Fri, 5 Sep 2014 11:24:18 GMT Message-Id: <201409051124.s85BOIdF080487@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r273686 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Sep 2014 11:24:18 -0000 Author: dpl Date: Fri Sep 5 11:24:17 2014 New Revision: 273686 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=273686 Log: Function name Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_pfil.c Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_pfil.c ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_pfil.c Fri Sep 5 11:18:09 2014 (r273685) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_pfil.c Fri Sep 5 11:24:17 2014 (r273686) @@ -91,7 +91,7 @@ typedef int (*funcptr)(); funcptr compile_code(struct ip_fw_args *, struct ip_fw_chain *); /* Pointer to the actual compiled code */ -int (*compiledfuncptr)(struct ip_fw_args *, struct ip_fw_chain *) = 0; +int (*ipfw_chk_jit)(struct ip_fw_args *, struct ip_fw_chain *) = 0; struct ip_fw_chain *chain = &V_layer3_chain; /* ipfw_vnet_ready controls when we are open for business */ @@ -133,18 +133,18 @@ int ret; /* If we haven't, JIT-compile the actions to be executed per-rule */ - if (compiledfuncptr == 0) { + if (ipfw_chk_jit == 0) { IPFW_PF_RLOCK(chain); if (! V_ipfw_vnet_ready) { /* shutting down, leave NOW. */ IPFW_PF_RUNLOCK(chain); return (IP_FW_PASS); /* accept */ } - compiledfuncptr = compile_code(args, chain); - ret = compiledfuncptr(args, chain); + ipfw_chk_jit = compile_code(args, chain); + ret = ipfw_chk_jit(args, chain); IPFW_PF_RUNLOCK(chain); } else { IPFW_PF_RLOCK(chain); - ret = compiledfuncptr(args, chain); + ret = ipfw_chk_jit(args, chain); IPFW_PF_RUNLOCK(chain); } return (ret);