Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1077396rwr; Wed, 3 May 2023 09:52:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ofurhg5doKG+usI+esDY6qoyZWg9f4HGncWe2TW9L8XVq1SnZZJVbbX+EQcWKiHPplJev X-Received: by 2002:a05:6a20:d48f:b0:f0:f2a:ff4f with SMTP id im15-20020a056a20d48f00b000f00f2aff4fmr21618531pzb.8.1683132777956; Wed, 03 May 2023 09:52:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683132777; cv=none; d=google.com; s=arc-20160816; b=pV47r0uXWMlOaWDd0qz5S31H1aLBeddNkGG1P61Cp9rYIHUvBHUiwy07xctQzy1Jwg OBCasfW9u8GMEP+HBqp2RLIdKF6QtR5zRvENz2aySRe4ltmRwb8dpbyQEi90+/4ylYcS cYcWe3N6+2hBIqNNwnt+rM5Wil6yamoTpNoGNTHLhCsbHQ5N/OIgzOIUu1riIZHoZAiR wpDPDjb6xRiyxd5vZn+afjp2htISv7obVjIg1FuZPkk/9ah0gusy/oWJOzy8g/521ROb SetX9e7hxvsCojbZWP63dBYKwZchRZjpLe5nqxv71lgEbOuB3jswL8tP78VJLkX0FEn5 woJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=CO3/wYgoteeIW67yC+Tl9a59Mskq9ceqxtoEpa1lobg=; b=GFGEq1yEv549xUP9W3o/zbBn+50LYg0Zh3RImydFwNRjrUnZqEtEHn1LOBGPUtIfSf fhuDnitDkwQQD9lDE5beQR8HGpvqnPvvuJyqrBMpwzI5DZBuzzOIAJNqOG22HeMb01o7 1sAvFHhhUB8AB5/EqxoUTfKMmTLk2ArvCf7nlPfUBV74jx1K8Ck38anSCiD/hMn5Hp5z ABfKngrVqYk61XwmI2k/8IvWS7dpM0nOHTD4LCYUHQleuXLfyITo9L6vlg1tE/F8hyFY JtlnF5heM+BeVTmqJzZML/mADlejQWaZ5iM6m6do+yt+GclVUKgR8HUIPg0VBNJqI82I 2PoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=U3V6bMyS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k12-20020a17090a62cc00b0023d23393318si13940277pjs.55.2023.05.03.09.52.45; Wed, 03 May 2023 09:52:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=U3V6bMyS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229659AbjECQiZ (ORCPT + 99 others); Wed, 3 May 2023 12:38:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229490AbjECQiY (ORCPT ); Wed, 3 May 2023 12:38:24 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 562C13C01 for ; Wed, 3 May 2023 09:38:23 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-9536df4b907so1095749666b.0 for ; Wed, 03 May 2023 09:38:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1683131901; x=1685723901; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=CO3/wYgoteeIW67yC+Tl9a59Mskq9ceqxtoEpa1lobg=; b=U3V6bMySLKAg6LVk8UPeUuN3y20ze+uC6keiE//AvpxAHHjLxpLgwbX5+U8B+H+OzG BIwHzjJxgiDL0l8fqRs4dHxvhbaaNpvXpkxOji9Iv8SWyZZioX7XFzlQZj0+u3PRJ1kr HTB0kBlM++ukjBH6tM98i5M0uvfDnc2jzt5Jo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683131901; x=1685723901; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CO3/wYgoteeIW67yC+Tl9a59Mskq9ceqxtoEpa1lobg=; b=S4XSv6lgobRh+YOx2JDGdWyV3FWq+wVeuXpfXqcO+beBrfn5WyXamvD87qez3ypvq1 8O+LbOza6OIyFi/PE7A+yvjevfJc+pMlHtKN+w/O8w3UCPdu4Iai/dpgZeHodw+3SA+k K5G0qN38F5PoqVzQrV0d1WGEChVuolQI9Q6cOoJKpucABZCQIRbDz99DACzs4bLGOzfc wo5GmJfPICMEo+HWVJ9lcuT8JusQ+tRoIr4hgI7u9cUuTRHL1rGwT9IjdMp2TrcGafB+ i3E4Phkp4mqYqIi/oqbruKZ1VpqQqyUJq25XSfIK52YvldkgpvidPFZVadSKWvkq/Skq 0Few== X-Gm-Message-State: AC+VfDyb9sFRVR5NkadXUdBYCJu2A8MXSgUKYG9KmI3G5fyyctIvfbV1 JIkHxoww5pTCq/U5HCvj922UoOv8+VansjR5U1MFGg== X-Received: by 2002:a17:907:805:b0:94f:cee:56f2 with SMTP id wv5-20020a170907080500b0094f0cee56f2mr4184925ejb.4.1683131901514; Wed, 03 May 2023 09:38:21 -0700 (PDT) Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com. [209.85.218.41]) by smtp.gmail.com with ESMTPSA id i25-20020a170906851900b0094f1b8901e1sm17539486ejx.68.2023.05.03.09.38.20 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 03 May 2023 09:38:20 -0700 (PDT) Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-94f6c285d22so1088857466b.2 for ; Wed, 03 May 2023 09:38:20 -0700 (PDT) X-Received: by 2002:a17:907:845:b0:961:8fcd:53c2 with SMTP id ww5-20020a170907084500b009618fcd53c2mr3430082ejb.64.1683131900304; Wed, 03 May 2023 09:38:20 -0700 (PDT) MIME-Version: 1.0 References: <20230427225647.1101172-1-dave.hansen@linux.intel.com> <20230429003822.n3mglslg666j3npp@box.shutemov.name> <641a9348-a052-6bb5-e6c7-64acb6405328@intel.com> In-Reply-To: From: Linus Torvalds Date: Wed, 3 May 2023 09:38:03 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [GIT PULL] x86/mm for 6.4 To: Dave Hansen Cc: "Kirill A. Shutemov" , Dave Hansen , x86@kernel.org, linux-kernel@vger.kernel.org, kirill.shutemov@linux.intel.com, Peter Zijlstra Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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 Tue, May 2, 2023 at 6:17=E2=80=AFPM Linus Torvalds wrote: > > And in the process I found another broken > thing:__untagged_addr_remote() is very very buggy. > > The reason? > > long sign =3D addr >> 63; > > that does *not* do at all what '__untagged_addr()' does, because while > 'sign' is a signed long, 'addr' is an *unsigned* long. > > So the actual shift ends up being done as an unsigned shift, and then > just the result is assigned to a signed variable. > > End result? 'sign' ends up being 0 for user space (intentional) or 1 > for kernel space (not intentional).. Looking around, this same bug used to exists for the normal (non-remote) case too, until it was accidentally fixed when changing that to use inline asm and the alternatives code. At that point the non-remote case got an explicit 'sar' instruction, and the result really was ~0 for kernel mode addresses. > Why does it do that "shift-by-63" game there, instead of making > tlbstate_untag_mask just have bit #63 always set? And it turns out that bit #63 really _is_ always set, so I think the solution to this all is to remove the sign games in untag_addr() entirely. Untagging a kernel address will "corrupt" it, but it will stay a kernel address (well, it will stay a "high bit set" address), which is all we care about anyway. If somebody actually tries to untag a kernel address, that would be a bug anyway, as far as I can tell. So I'm going to just remove the 'sign' games entirely. They are completely broken in 'untagged_addr_remote()', they _used_ to be completely broken in 'untagged_addr()', and it looks like it's all unnecessary. Linus