Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3923429ybf; Tue, 3 Mar 2020 15:56:45 -0800 (PST) X-Google-Smtp-Source: ADFU+vt51Gd5uvjMupkbVvCo4o/wlgweS7WFmSxFWUDkgo2kBPRRZINWzq4+uCV5aTfYjZvsCW7t X-Received: by 2002:a05:6830:129a:: with SMTP id z26mr303868otp.179.1583279805337; Tue, 03 Mar 2020 15:56:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583279805; cv=none; d=google.com; s=arc-20160816; b=rGmoFShNFGIHl6nvhkqJJ0Xty3AKpbTUAKYtYqLUHl+QBK4Fj05ljKGnIpluNVvG6b MVKvfakqW38FM/N9bDao4znAMcE65ov82l3HQCaqxovu3T90XNfVdqiQbavERpSaaaGv CYFyGT8lcee1UPJs8QDsmkJUr8ZdmMcvptez8zBCquoWEt7TX0TJej6M+zx4vQki5lM+ JHdLQjIfcvNTvQAIWErj4RWQKLmUvDCxEBVwcdvp5EhlnXud6ZCMi82B6OUXN5wihtmX z1q85Fk0k37+S6WHfA3qbAEoZp4abC38JR7+xwSvjM+hL1V8mmtVoV+zXisvd6sBuZZO IjkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=y8gDt4+hKLFEVUT2875HZHL2GUBm9at3uoIUJ/mCCI4=; b=iLQ16h/4TLHvg8MgZWPTY6qmYYswPjtUjm3aR+gm5frxLKgUDif7Y5ZIeDjaUzEXAA mZDVCAebY1naFtWDLKJRdCdpf2L9yUwWvpPVuTCbamirU9im/Tc9hUA6YQqChi7Tihno 0FQK4ay5+s2vtHx/d2jFvja4yk0bxnLbmZPQdkWmdoplS0OHE+OjuCJYkivE1heKfHVB jLZ/U2sPGoBkR+leGqf4dpMz5E3b7syOTQiNoaa6WheMC9xzqQCxh7j3MO8yKVeIH/aC IcvrZPQANIVvegMeYpg6NVaRVBEelM9qBMejH2x6YJxf0ckG16Idc+gcSgazasrzLsUw m3fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EWc6ytjv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l1si91064otn.213.2020.03.03.15.56.33; Tue, 03 Mar 2020 15:56:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EWc6ytjv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727870AbgCCX4K (ORCPT + 99 others); Tue, 3 Mar 2020 18:56:10 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:40271 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727707AbgCCX4K (ORCPT ); Tue, 3 Mar 2020 18:56:10 -0500 Received: by mail-pf1-f196.google.com with SMTP id l184so2329724pfl.7; Tue, 03 Mar 2020 15:56:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=y8gDt4+hKLFEVUT2875HZHL2GUBm9at3uoIUJ/mCCI4=; b=EWc6ytjvGgIM9CPsIuRtdRj7fSSnF3G0MyQk/9TJkcVNCTJcp8ob0LqyblK66ZjQ/y hArGfUegHFur9Flsc1QdJdVrI25B8ycSY5oBB6K2c8bv7zDQATa/DI3E0xux1EejQafW s/Psl9Dn5u6QMtFhpLs1MvV6FQSuGoS9ZkIaFIAmbbN3DfFUhAeXSqS/ZB0K9OS4wMEx ZKO+lD3dLySP0/Q2Ua2PwsQCfeynrKfoBvvK6jFiUEgT0gK7fE7nStmFZiRpOQcQRCPu ShyndO2nUCe/gUhrGR5ElWkW4zxmwkccuxBJXCZ/ma3FHmL1+pkMVL1sYtFwKYjMMxs2 V1nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=y8gDt4+hKLFEVUT2875HZHL2GUBm9at3uoIUJ/mCCI4=; b=C7b+2X6gbrEpxRHwxZRpzmG1YwQ0rmyhpmt4Kx3eq3Wenf0KR46PFhN7vfv6/F13OE 4QAjkYG1/zJfTynwnzEyw5tm7yLEVTXB2hciffSvuoAgRjZk2A57/+CTas3jfmONqkZ2 P4OsYVroI9XoBwn0YSJ54i61GjRaW3iEU2MqEnqm7DAfyU7WSumWE5mXNSTY938pM9p9 A7jb/2fluSW/tKlJidmmXhfCkAbwH2T+4/vbZfzIyP0Wuxd7Y+KWWpWDDndhEEvxgWM5 NzlRp/N8y1w88OiEuVDU8rSH6CWcasNYTd/R6MzIx8P8NMQDhpUaPIhHCRMI53cWSVEv ebpg== X-Gm-Message-State: ANhLgQ3Z5FJJJlMyP1GSibhcP1zEQMNJLvzaaohwnp21CSq3bxJWJZTE Uxkg2q7j/Js6sddwJkEuNfhNZkM+ X-Received: by 2002:aa7:9a96:: with SMTP id w22mr232054pfi.210.1583279768806; Tue, 03 Mar 2020 15:56:08 -0800 (PST) Received: from ast-mbp ([2620:10d:c090:500::4:a0de]) by smtp.gmail.com with ESMTPSA id u5sm3262803pfb.153.2020.03.03.15.56.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Mar 2020 15:56:07 -0800 (PST) Date: Tue, 3 Mar 2020 15:56:05 -0800 From: Alexei Starovoitov To: KP Singh Cc: Andrii Nakryiko , open list , bpf , Alexei Starovoitov , Daniel Borkmann , Paul Turner , Florent Revest , Brendan Jackman Subject: Re: [PATCH bpf-next 2/7] bpf: JIT helpers for fmod_ret progs Message-ID: <20200303235604.mdlamwx4z2ws3fzy@ast-mbp> References: <20200303140950.6355-1-kpsingh@chromium.org> <20200303140950.6355-3-kpsingh@chromium.org> <20200303222812.GA5265@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200303222812.GA5265@chromium.org> User-Agent: NeoMutt/20180223 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 03, 2020 at 11:28:12PM +0100, KP Singh wrote: > > > +static void align16_branch_target(u8 **pprog) > > > +{ > > > + u8 *target, *prog = *pprog; > > > + > > > + target = PTR_ALIGN(prog, 16); > > > + if (target != prog) > > > + emit_nops(&prog, target - prog); > > > + if (target != prog) > > > + pr_err("calcultion error\n"); > > > > this wasn't in the original code, do you feel like it's more important > > to check this and print error? > > > > also typo: calculation error, but then it's a bit brief and > > uninformative message. So I don't know, maybe just drop it? > > Ah, good catch! this is deinitely not intended to be here. > It's a debug artifact and needs to dropped indeed. That spurious pr_err() caught my attention as well. After further analysis there is a bug here. The function is missing last line: *pprog = prog; Without it the nop insertion is actually not happenning. Nops are being written, but next insns will overwrite them. When I noticed it by code review I applied the patches to my tree and run the tests and, as expected, all tests passed. The existing test_xdp_veth.sh emits the most amount of unaligned branches. Since then I've been thinking whether we could add a test to catch things like this and couldn't come up with a way to test it without burning a lot of code on it. So let's fix it and move on. Could you rename this helper? May be emit_align() and pass 16 into it? The code is not branch target specific. It's aligning the start of the next instruction. Also could you add a comment to: align16_branch_target(&prog); for (i = 0; i < fmod_ret->nr_progs; i++) emit_cond_near_jump(&branches[i], prog, branches[i], X86_JNE); kfree(branches); to say that the loop is updating prior location to jump to aligned branch target ?