From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07358387374 for ; Mon, 20 Apr 2026 22:00:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776722443; cv=none; b=OAwfCqSgh6hDq6+kp/zvsbcZJezcEN3rSxf1burWL27PRtYmMfQb4QAtR5wS5/FgP6K8EdndxFCjZ22CMdbtMeh9o9vaQbDFpk13F1/g5OBguziRU84VRlX/AyLMuirotbtMViNZ2NkeTC1fnDcDcjMZnp5n4INkoYOAcC146bI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776722443; c=relaxed/simple; bh=zcIuX44FQ4JZplZlzPi2l4ZSnMwkpRIbGnceAVAp6cg=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kPS9QDzMiwoUoZlg3gd71hkKHiHpdF3a+o6VBikqtyFfVDA0kj6A1CjnEcIvkMOB5FRjDV3W7Q5WbrqLf7Jf/keFQK0bis9pTA/xxxiV7otpkCUSU4Ao7IU9ufzAKYtYwbCm5PmCo2eYQLHrslRzs6OSH6KzjK+BSyxSeqfhReI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kAReCENy; arc=none smtp.client-ip=209.85.221.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kAReCENy" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-43d74086e5bso3522887f8f.0 for ; Mon, 20 Apr 2026 15:00:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776722440; x=1777327240; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=+7JO2f/xlDpOxtBT93GnNbMq3RmdZ9DsCL97xFYueTk=; b=kAReCENyQnUWaL/fzwM1HV0Iz4JNWHfQYDT+hEHCcnneS2miPKABJqXU6DBOguxZKS T+owt/hFSTq799Zq6ejr8MfRapAGqczgxrn/8/FSKbE4KmN2ecbAPCxl0IncFGwJTXxJ nLKB7sB3vG6SkQH2/xRRbRyCNxGQLGcXSEM/lZ3EydQTt+k/28Voi4lzCueMszLE9MQU MNmU/BmLUUxnUGI5vDtsusUgwIOBaCNde5y2QQ8c3lQ0RVjTWmuoH5l+htPqfA6o0t9v VEcoOG5uXV5v1ERu+jg2x5BELqnbOExZVcrhsQF9tEDo8NaLFrZbDn2mXtDgg+BpshvP X1Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776722440; x=1777327240; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=+7JO2f/xlDpOxtBT93GnNbMq3RmdZ9DsCL97xFYueTk=; b=KlD8yB7HxAJwunqFqjSNCUmRACLCNBSl3UNfkbZxhc7Za6HkcVzcB1MOQ1RZjdPx0Z Pgl61XcVjs6o+WvATNqESgO6K2Q+sISCi3FbgrlfPnxEPshrRwYCXsct8/SQAIyKqJ1A cXQngPzKhZpwKSbe2m240KCEDWCJKOlX06ZGhBfMMwA9zpntX7S+7uIhXDOpmAvepWvp z56OY1TRsSIJz9bWjAULi0BgVlu5PDkKJWoUyAEo6EOtdtMHMNnB3z0XGi+/DcFhcbGp Jb9m34LonETLIL07aLEBxNWfRvmmdz1PB3aTrRad2+TeBPCzIvPzGzql8z2uLQRb38r9 K/VA== X-Forwarded-Encrypted: i=1; AFNElJ8HHD3BYF1BVowYbIR1Jd2/2FfJTjZT+3zj+8wGjKo/p5i44+aINkJ7Hzjj8ByG0iMp6vJ16ec=@vger.kernel.org X-Gm-Message-State: AOJu0YwxNC17fnL+9AaDIVQZ15XQUQv2kQhdCFRsMVvSa9ObgeXbj12M e5afPjRbKRaZYBHHqCNDTG1xfatUOh4By0GDLWJEsg6xMwbi4JaEzIhm X-Gm-Gg: AeBDiesJF/4lhIRT1/Qxg2VclrFoztBpBBnM0CdsT5wNLuNizWq1hASHt9+wMmeIdKU NhWO1Phbz1jCVgQ7cayHwZdCIsac9DemNM008moLAqfz5wctMXSh4dPDrUPHhBCm9TS1enX/DeW srLCbCeRsEsR059qOp8PvaAw0tR9EyHegsYTqJ6RznV9pYASjC+7AaR3GDQp0u6iqGPjPRKZlKD KMbu8+Aeoh9na9Erk8hOZwtFXnBGZeZUURS/nyUA40GXe/YTemcuAxsx1Pa5IvPzXiiW7K1ZcYZ 4HCI70tZmAPStRrkzwd4QfmuClDHKa6cE/9hgTHB5nN87Q0aPeN/5nJdFP/+qO0xU71a/ykB6CK 90oZCrqObxxjnL5YZr1+KPuM1b/zfSPGhqzic11tY+V/zsWxMf/PIYzXvMEGeHoD3CCIH/KYceW 57NwW1XItOAwusTSkw6g4POouyyMgTOWMklpAtB20IS2343FjhPKICI59c63plYgV2WGjGdkqBU I0= X-Received: by 2002:a05:6000:2303:b0:43e:b020:f8a2 with SMTP id ffacd0b85a97d-43fe3dd5208mr22198611f8f.19.1776722440147; Mon, 20 Apr 2026 15:00:40 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43fe4dc26a3sm36471952f8f.15.2026.04.20.15.00.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Apr 2026 15:00:39 -0700 (PDT) Date: Mon, 20 Apr 2026 23:00:37 +0100 From: David Laight To: Yury Norov Cc: Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andy Lutomirski , Jonathan Cameron , David Lechner , Nuno =?UTF-8?B?U8Oh?= , Andy Shevchenko , Ping-Ke Shih , Richard Cochran , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexandre Belloni , Yury Norov , Rasmus Villemoes , Hans de Goede , Linus Walleij , Sakari Ailus , Salah Triki , Achim Gratz , Ben Collins , linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-rtc@vger.kernel.org Subject: Re: [PATCH 2/9] x86/extable: switch to using FIELD_GET_SIGNED() Message-ID: <20260420230037.21fb4758@pumpkin> In-Reply-To: References: <20260417173621.368914-1-ynorov@nvidia.com> <20260417173621.368914-3-ynorov@nvidia.com> <20260420112428.GF3102624@noisy.programming.kicks-ass.net> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 20 Apr 2026 13:18:47 -0400 Yury Norov wrote: > On Mon, Apr 20, 2026 at 01:24:28PM +0200, Peter Zijlstra wrote: > > On Fri, Apr 17, 2026 at 01:36:13PM -0400, Yury Norov wrote: > > > The EX_DATA register is laid out such that EX_DATA_IMM occupied MSB. > > > It's done to make sure that FIELD_GET() will sign-extend the IMM > > > field during extraction. > > > > > > To enforce that, all EX_DATA masks are made signed integers. This > > > works, but relies on the particular implementation of FIELD_GET(), > > > i.e. masking then shifting, not vice versa; and the particular > > > placement of the fields in the register. > > > > I don't think the order of the mask and shift matters in this case. If > > we were to first shift down and then mask, it would still work (after > > all, the mask would also need to be shifted and would also get sign > > extended, effectively ending up as -1). > > FIELD_GET() doesn't require mask to be signed when a reg is signed, so > shifting mask may become zero-extended in an alternative implementation: > > (reg >> __bf_shf(mask)) & (mask >> __bf_shf(mask) > > This all is hypothetical, anyways. > > > But yes, this very much depends on the signed field being the topmost > > field and including the MSB. > > This is the part I dislike mostly. This would look just like undefined > behavior for the API user: depending on fields placement or type of the > inputs, sometimes FIELD_GET() sign-extendeds the field, and sometimes > not. > > We could likely force FIELD_GET() to treat both reg and mask as unsigned > types, and state that explicitly in the documentation. > There is already a BUILD_BUG_ON((_mask) == 0), changing it to >= 0 will detect negative masks. I think the only one is the x86 exception table. FIELD_GET() casts the result to typeof(_mask) so the sign of 'reg' shouldn't matter. I just tried building with a compile-time check for reg being negative. But there are too many false positives from FIELD_GET(mask, readl(addr)) and FIELD_GET(mask, READ_ONCE(var)). The pre-processor expansions of those don't bear thinking about. It's late now, but I will check how __unsigned_scalar_typeof() handles variables with const or volatile qualifiers. I think they do though the 'default' the same at bitfields. David