Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp376386ybz; Tue, 21 Apr 2020 10:43:26 -0700 (PDT) X-Google-Smtp-Source: APiQypK0utIjr5N23ujNdp/so9k6KmXIH5AZjYP4pKTUcBGIgjVAjeed50XzAMhLz4iNqCvcl+eV X-Received: by 2002:a17:906:304d:: with SMTP id d13mr8772311ejd.159.1587491006359; Tue, 21 Apr 2020 10:43:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587491006; cv=none; d=google.com; s=arc-20160816; b=rAsW8luBDw7VsAS8BmcI+hOzbig8fef/hPtL6csTpSIV2SN0nz4XVzAFpqTnnPFfdG b8++2rgALSRyyebtAr05bpekSY6TLEVaOq8S7G8EasFIqd70dCUGXVoLoJkw8v37FSBr l9oKHevNPetUMg0A8h9uiGytez7u8E+w8toDJtNpw+7+6+Umm4Qt6KGNBX5evM+8t2x7 tRxscsl8BwdzJTbruOaWL9usGe4aMuNl/0tYuPpUxwnJlyq432Rtb9352uG/Tg493G+s SymQRcqckzAWLHvbtYRFnBt+tFSlTYn5mN3fx0mhJ/5An4dT1LnnPduJcHgfmPhY3MNO QdPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature:dkim-filter; bh=2eEU+EJFQOujIVEE8U93Ltuhe2VZbe2J6MQcshNq8Gc=; b=xYII2ssVyrcCYQcTWxUViQSjIPUPFFakvg6E3swOLBna0f7vre5YH2oSKfHQZptojz 7/23L26YRLvdw2wp9///lm46a+TB1Pu+HhjYYxMEycbNR53Cn8SBBpoTwUNszZPYo4Ba pdR1iR0utzTqbtgAWBjTA/dthumN4uKRCnudiertO/AXt7NiAUk9J7N2YEEXAtftbMOw CZwvw7XO0OwWHk/GZOOeI2RxzfrWnOT2ZXRSTX2PwExZXYFWPSQ699pxX/21RawD/6tI KT+c2bADJLj9oGMLVd3+fp5VGinuiofASIlULJoazWU4evuQdb56sVyHHwfBHAwt/oLQ n5Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2020032201 header.b=FRu+zW3a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c13si2011176edq.97.2020.04.21.10.43.02; Tue, 21 Apr 2020 10:43:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@zytor.com header.s=2020032201 header.b=FRu+zW3a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729302AbgDURkT (ORCPT + 99 others); Tue, 21 Apr 2020 13:40:19 -0400 Received: from terminus.zytor.com ([198.137.202.136]:57271 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725963AbgDURkT (ORCPT ); Tue, 21 Apr 2020 13:40:19 -0400 Received: from hanvin-mobl2.amr.corp.intel.com (jfdmzpr05-ext.jf.intel.com [134.134.139.74]) (authenticated bits=0) by mail.zytor.com (8.15.2/8.15.2) with ESMTPSA id 03LHd4SZ1367462 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Tue, 21 Apr 2020 10:39:05 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 03LHd4SZ1367462 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2020032201; t=1587490748; bh=2eEU+EJFQOujIVEE8U93Ltuhe2VZbe2J6MQcshNq8Gc=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=FRu+zW3aT1xB/O9RhVPpuaCU1a00em4UZGRUXlpI8adUD4oxWt3N3O4gQSAs8ktqX GMSwtqLpOpUyQd7tnA4svUvQNn++7WjDPRDzbPX0iCvp1MTB07sv/vM7ljC7UfIo+5 ixGBAYj0t1brz5FO9eL9cICHKXvbiywjDXllHcD+y7iEsxcD73eNW5XpUlysWujhUY thY8dgONC2pH3wDnNTFlBxeSzrJaLF/PbAOpKrNJleFbRpMX+XzWnTRwwaCqy7a0KX UwUd3BqQ8mAWhzckyRBmQJKdsx/8PLZZ/OOaTE2xN0bRv/YbVdsKDZZuZqPg4z0lZ8 4tr7BuUBIzp8Q== Subject: Re: [PATCH bpf 1/2] bpf, x32: Fix invalid instruction in BPF_LDX zero-extension To: Luke Nelson , bpf@vger.kernel.org Cc: Luke Nelson , Xi Wang , Wang YanQing , "David S. Miller" , Alexey Kuznetsov , Hideaki YOSHIFUJI , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: <20200421171552.28393-1-luke.r.nels@gmail.com> From: "H. Peter Anvin" Message-ID: <6f1130b3-eaea-cc5e-716f-5d6be77101b9@zytor.com> Date: Tue, 21 Apr 2020 10:39:00 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <20200421171552.28393-1-luke.r.nels@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-04-21 10:15, Luke Nelson wrote: > The current JIT uses the following sequence to zero-extend into the > upper 32 bits of the destination register for BPF_LDX BPF_{B,H,W}, > when the destination register is not on the stack: > > EMIT3(0xC7, add_1reg(0xC0, dst_hi), 0); > > However, this is not a valid instruction on x86. > > This patch fixes the problem by instead emitting "xor dst_hi,dst_hi" > to clear the upper 32 bits. x32 is not x86-32. In Linux we generally call the latter "i386". C7 /0 imm32 is a valid instruction on i386. However, it is also inefficient when the destination is a register, because B8+r imm32 is equivalent, and when the value is zero, XOR is indeed more efficient. The real error is using EMIT3() instead of EMIT2_off32(), but XOR is more efficient. However, let's make the bug statement *correct*, or it is going to confuse the Hades out of people in the future. -hpa