Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1034756iob; Fri, 13 May 2022 20:28:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLJxZlyMA67TjCGDPflTD+azAfi+LZiXlqAWGuzhC0Omv1H6h+bqfAg/TN7Mnq3X85WADf X-Received: by 2002:a05:600c:3658:b0:394:725:be12 with SMTP id y24-20020a05600c365800b003940725be12mr7153956wmq.192.1652498895376; Fri, 13 May 2022 20:28:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652498895; cv=none; d=google.com; s=arc-20160816; b=TudBdaus8YP2AUVyn+pY3NJVzjZW+KacOXM4kOtyaPineJOwqEkDkAwq1JNSBPNs7U fuvzeqxt9onuHREtBhOzmmoPHcuj3UfbgQbM1oRKOEFomQaq+a3rWT6duTYbfGok4YBb /0AKWbj75LL+dLlHC/DPjRPIbWXGKhXL7ORmZL9TuVGsK0BwozTkNB17hMMF1AP/nLkf vFE3r6NN7kouJ9KNse3+RdASZqoeGPeOWW2pdR49FoRXlSdBNkWVxE1UQb0rqNz7eao2 dQZ3RXXXsS1kkXYkU0/dLctLA0AhStayj0oISbiONIblTqC70AI68ElkeeFSUZuaLvF9 NMkg== 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 :message-id:date:references:in-reply-to:subject:cc:to:dkim-signature :dkim-signature:from; bh=kFygtcm883Zn7/U1NS2HdSj+Xtje9N7wIaflQX84+U8=; b=RByEkC8KJcQk0FAUUJb6tptXBHFK9Vm5kdGV7eJAi2UoiPJEaaK10NZ+hsSsyWe6Xb SlMBexQpDve4NXIofanufDUIdDZK6ox0Cc+bkI8h+Kk/idVtdlnzrKcCtwz8uK35KGnM SyoutGDRXTQ7oAtuBXJE6ptpUiqyfcQl1zHEt86i+l+VXvz/YPsfH+SIO+U9dq75B8oO nXsy2UBc6aklYLd79bY1enE8K5WZbmu7tZ1YESFJlwVlW2huvY24zVkt52OU3zJDCpxz ijrL8JEdT4IWmPQxfY/vFnOvUvfumhKVfL7TCCO5XsLSHhssl/jpsFZVeWqTorXXr3WE Ei6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=GJpd2woi; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=UNXNdwBv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id bg36-20020a05600c3ca400b0038c77be9b75si3868265wmb.144.2022.05.13.20.28.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 20:28:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=GJpd2woi; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=UNXNdwBv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 67EB741A204; Fri, 13 May 2022 17:05:02 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355383AbiELPGp (ORCPT + 99 others); Thu, 12 May 2022 11:06:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355399AbiELPGo (ORCPT ); Thu, 12 May 2022 11:06:44 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88D11140C4D for ; Thu, 12 May 2022 08:06:43 -0700 (PDT) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1652368002; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kFygtcm883Zn7/U1NS2HdSj+Xtje9N7wIaflQX84+U8=; b=GJpd2woictX7Fls9i3IfIphhaUayBlAS3b4PEjVgPONw5SpQ2fw1Yiln94J2NiAM78N32a mofbSXJW6uen5cZ03EJT/S2no4dWq1a7Z/GA9v7w1a95sCpFOHBRir4Z1HEYZV+31tf3NS OQCFUIRi58qXjKNH6TyzjxpS4pQOnZxLBkZ28Y1uUvJDb/K6gx5nWHbTfnarxoH4/dc1CS QXD4zPOpz7ri6Qllw5uEnzwDMGmpLlwOAkoTX98SIKJqY/o10GkDDQajHvRlDiz0mBTfLo wXM4hoLXt7X/by/kgcKEotA181TJFe82HMuUy0ZyU3hef5Oai8y35NBCOaSCaQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1652368002; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kFygtcm883Zn7/U1NS2HdSj+Xtje9N7wIaflQX84+U8=; b=UNXNdwBvHezxPiv2SBK2qV8ueGqfJ/UmvrnNZiwaCWbXQ9YfMDKaVG3M0SUOyjtHshhcYj Sz5rUorlkuTFlIAA== To: Matthew Wilcox , David Laight Cc: "'Kirill A. Shutemov'" , Dave Hansen , Andy Lutomirski , Peter Zijlstra , "x86@kernel.org" , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , "H . J . Lu" , Andi Kleen , Rick Edgecombe , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] x86: Implement Linear Address Masking support In-Reply-To: References: <20220511022751.65540-1-kirill.shutemov@linux.intel.com> <20220511022751.65540-2-kirill.shutemov@linux.intel.com> Date: Thu, 12 May 2022 17:06:41 +0200 Message-ID: <87v8uavlha.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 12 2022 at 15:07, Matthew Wilcox wrote: > On Thu, May 12, 2022 at 01:01:07PM +0000, David Laight wrote: >> > +static inline int64_t sign_extend64(uint64_t value, int index) >> > +{ >> > + int shift =3D 63 - index; >> > + return (int64_t)(value << shift) >> shift; >> > +} >>=20 >> Shift of signed integers are UB. > > Citation needed. I'll bite :) C11/19: 6.5.7 Bitwise shift operators 4 The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits are filled with zeros. If E1 has an unsigned type, the value of the result is E1 =C3=97 2E2, reduced modulo one more than the maximum value representable in the result type. If E1 has a signed type and nonnegative value, and E1 =C3=97 2E2 is representable in the result typ= e, then that is the resulting value; otherwise, the behavior is undefined. This is irrelevant for the case above because the left shift is on an unsigned integer. The interesting part is this: 5 The result of E1 >> E2 is E1 right-shifted E2 bit positions. If E1 has an unsigned type or if E1 has a signed type and a nonnegative value, the value of the result is the integral part of the quotient of E1/2E2. If E1 has a signed type and a negative value, the resulting value is implementation-defined. So it's not UB, it's implementation defined. The obvious choice is to keep LSB set, i.e. arithmetic shift, what both GCC and clang do. Thanks, tglx