Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp66969pxb; Mon, 13 Sep 2021 13:07:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUQFcfTrReuQj9otgbtdkynEQ2g1yzPjM53pDfLZoGoShDmpiglUfKoM+lvhFGBUcPPdX3 X-Received: by 2002:a05:6402:1385:: with SMTP id b5mr14676080edv.276.1631563637270; Mon, 13 Sep 2021 13:07:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631563637; cv=none; d=google.com; s=arc-20160816; b=n1u1Vz9oJM4v0yCFoMVFTUcA7uJtnwtha0j4ZmsrOV8i9lCAT1RMBlLNqK4UHp2MGK n57xzXsWnLplgDsGvIuvezZDpXlL9wlLgAJINIy2TMwsry7srJTWM9Wpcalzfsu+X9qr BdIUFed0xbmRtSjab0/R98S+kOzS9z2NhhnQVJXBoNmQpDgL7RdeFnj3ADBy1EdxtMDX 0BdRa1ENrDvtp4LbYD8LHIHhAYrIZhc5eb0Fs1frz6awirKQqDrOE5Hs7j6Nz4UK7AH5 Ptr+YtWUOitivGPij3T+U/EXibZF5p0rI0l6RqE6wP+AyRJBLwTW0zSXSBaRJykKISyJ O9Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qyM26VHBG6cx1FvfzKPcvKlYel44HBPJACWjbzu+RZA=; b=ZmItPgexdQeNNo2nPyHfKaMrkZ2Puya5Ftpupxqa4l2f8bnSf6dsxpyCxjCZRSXQML b/C34zpdNfzY4VLM1hyZHwLxaWwQJHGTyemedk/EJcaku8lWW8NAM3pJZIV7Uc22jlPB 4EVLQyhp+0ISACr9HcCATW4KCJ1PvfX+/ITd+djWml9KMIq3iwLiPqQrfmDZUAAiZsKJ nWZO6WvQObHey95e0nW4xb2mzM2ZHdn0PkZ3PJzgwz3411MVNDDZ9gfYHq9Q5b/lAF5Q w/CB8HyXDO8GErrEjtdv3WSmb08MCZwHLK3IrkSbcbQ0dHMF0dw7um2jTUEgMQZ6xqhN QJBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Kv6chbJY; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f12si8003404ejf.532.2021.09.13.13.06.52; Mon, 13 Sep 2021 13:07:17 -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=@linuxfoundation.org header.s=korg header.b=Kv6chbJY; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241737AbhIMNqH (ORCPT + 99 others); Mon, 13 Sep 2021 09:46:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:41194 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241689AbhIMNkp (ORCPT ); Mon, 13 Sep 2021 09:40:45 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0B8D661401; Mon, 13 Sep 2021 13:29:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539771; bh=lt2d/6xG79Pm5RiHOz0sUo5GqEsJxbZVv/fJEDxiuOA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kv6chbJYumCaITM9yspy/DDBdQzn8m6fI4Q/A5OQrOH6Vcqq4jq6fcllIic9+orei 4R9a7wCNBJoANsR5Kj030m6KRzTE3euKmBDfCykpe+6ZcFzE2fvz8zChGeTU9NBnod Je7ZDm6A0kvGfghxhAjeIVhqKDmobFxu6zVGLn3A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ilya Leoshkevich , Andrii Nakryiko , Sasha Levin Subject: [PATCH 5.10 154/236] selftests/bpf: Fix test_core_autosize on big-endian machines Date: Mon, 13 Sep 2021 15:14:19 +0200 Message-Id: <20210913131105.611298619@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131100.316353015@linuxfoundation.org> References: <20210913131100.316353015@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ilya Leoshkevich [ Upstream commit d164dd9a5c08c16a883b3de97d13948c7be7fa4d ] The "probed" part of test_core_autosize copies an integer using bpf_core_read() into an integer of a potentially different size. On big-endian machines a destination offset is required for this to produce a sensible result. Fixes: 888d83b961f6 ("selftests/bpf: Validate libbpf's auto-sizing of LD/ST/STX instructions") Signed-off-by: Ilya Leoshkevich Signed-off-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20210812224814.187460-1-iii@linux.ibm.com Signed-off-by: Sasha Levin --- .../selftests/bpf/progs/test_core_autosize.c | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/bpf/progs/test_core_autosize.c b/tools/testing/selftests/bpf/progs/test_core_autosize.c index 44f5aa2e8956..9a7829c5e4a7 100644 --- a/tools/testing/selftests/bpf/progs/test_core_autosize.c +++ b/tools/testing/selftests/bpf/progs/test_core_autosize.c @@ -125,6 +125,16 @@ int handle_downsize(void *ctx) return 0; } +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#define bpf_core_read_int bpf_core_read +#else +#define bpf_core_read_int(dst, sz, src) ({ \ + /* Prevent "subtraction from stack pointer prohibited" */ \ + volatile long __off = sizeof(*dst) - (sz); \ + bpf_core_read((char *)(dst) + __off, sz, src); \ +}) +#endif + SEC("raw_tp/sys_enter") int handle_probed(void *ctx) { @@ -132,23 +142,23 @@ int handle_probed(void *ctx) __u64 tmp; tmp = 0; - bpf_core_read(&tmp, bpf_core_field_size(in->ptr), &in->ptr); + bpf_core_read_int(&tmp, bpf_core_field_size(in->ptr), &in->ptr); ptr_probed = tmp; tmp = 0; - bpf_core_read(&tmp, bpf_core_field_size(in->val1), &in->val1); + bpf_core_read_int(&tmp, bpf_core_field_size(in->val1), &in->val1); val1_probed = tmp; tmp = 0; - bpf_core_read(&tmp, bpf_core_field_size(in->val2), &in->val2); + bpf_core_read_int(&tmp, bpf_core_field_size(in->val2), &in->val2); val2_probed = tmp; tmp = 0; - bpf_core_read(&tmp, bpf_core_field_size(in->val3), &in->val3); + bpf_core_read_int(&tmp, bpf_core_field_size(in->val3), &in->val3); val3_probed = tmp; tmp = 0; - bpf_core_read(&tmp, bpf_core_field_size(in->val4), &in->val4); + bpf_core_read_int(&tmp, bpf_core_field_size(in->val4), &in->val4); val4_probed = tmp; return 0; -- 2.30.2