From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 F2E8B38655B for ; Mon, 20 Apr 2026 22:00:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776722443; cv=none; b=g16jnlyD8zBTJTQCusclf0k8/thLa/t5laDFhZ5pAb6lY/WEGA24boT2Mmp3LF/hNZuSseCa0MQMpe1MHuTYUt60LFLGAcer9po0PxzUINS6CwzcYsL1dcl27hJcI0MF6QnA6AUDz8SGcnvqGrZwvPnMkmI9LLIPp5IdL5q+UNE= 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.44 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-f44.google.com with SMTP id ffacd0b85a97d-43d77f60944so2883287f8f.3 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=suYZA55DnTQ/9peM+jv5Uqkdo6+qzLyfN+MLxhRvnQAecIGWbk4BDiXDr+IWGbPQ9/ 6y1n6HXQXKnzE1ANYFw7ehzXNd5CJRYV5zK4/978nTDyd2FFi6SWu9KZPGuc2qHIOR+l esNBJrDBWp5HDc4jbjy2S9iWohzrNqaQIz7vk3KUpSNDFuOdAM6uSoONrLltYVEo/cq1 4k03S7G0NuSo0dZTRKbRhFUXKX8TZr2zL7+WwVBQtGn3Js6NTMTXwdeZAvrvwf0qg4uX CC72COHtTpDyuRms4DQQ0C1UNDWtsPWVkso/cDtIgVttg+fqQRzb//2+eTa5nPYOUkas rZUQ== X-Forwarded-Encrypted: i=1; AFNElJ+0MVR2wRXzOAh8QDXU5zHjrIsR2y8IFCVCiMxPTgf3LKTaAOjXPtr3RtkGprmqlF9GAj8i34/7eGzdL5Q=@vger.kernel.org X-Gm-Message-State: AOJu0YyNYRZqMfg81+rsp4Ae470PUTL6BinqvfYt5EJV9C+S+MSxgBmV 0xeqItGW9c3RNp+zZ4+0nxnmNZ0unRxoxdZ0AgSzoA60cayqyliWkJWs X-Gm-Gg: AeBDievqlRSoo2r53RjaCQ0/5NIMrczvmEO5FRHSWE/xDjbWXNHHVkuGFTAZMGP8V8V aGjmS+uJXncQ382Adj3zKGzh/UkU54ZRkboBfdGemN8Uwce9eGYy7mSJzY0Kr69OuzTCgRaTTJp +WY84G81N5JkzsOR8KY97ZPMhS8P4yiUgT5IRP01+v9kVLdJC1EJFwmaCtLcqTfeIGWH10CTn3o 4z/WgepMpJVeZm8MNdNEVWfQl4OdjStdqMKOcY4eI9cDNv0s239eSDU2TVefaJ/8EMn4IRz2sxZ 0sqmSdz9IKTdOxtPSl49khJZC6Ma85obT3CWbtC2H1Ht3ViGZrR6sgbp+/f70KdnYp+UYestxd3 WuZupBwkuZhs0Rrlq8mdyNUv6HAUTOnQhEveRfmGzLhGVo8OQScerDpgnpMqYnPfoREMEb/g4xO 4sbsTS8hMlo+Vj0CeauiOwd8VZMDo7T54kfailRRnTxaUPHHH+WHUy69rg/05qn8Kykg46SK73O n0= 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: linux-kernel@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