From patchwork Mon Apr 29 13:01:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13646907 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D0A58C4345F for ; Mon, 29 Apr 2024 13:01:34 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.714053.1115027 (Exim 4.92) (envelope-from ) id 1s1Qcx-0007Dn-Qs; Mon, 29 Apr 2024 13:01:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 714053.1115027; Mon, 29 Apr 2024 13:01:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1Qcx-0007Dg-Nu; Mon, 29 Apr 2024 13:01:03 +0000 Received: by outflank-mailman (input) for mailman id 714053; Mon, 29 Apr 2024 13:01:02 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1Qcw-0007Da-L9 for xen-devel@lists.xenproject.org; Mon, 29 Apr 2024 13:01:02 +0000 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [2a00:1450:4864:20::336]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 86da2ce4-0628-11ef-b4bb-af5377834399; Mon, 29 Apr 2024 15:01:00 +0200 (CEST) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-41b869326daso20377545e9.0 for ; Mon, 29 Apr 2024 06:01:00 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id q13-20020a05600c46cd00b0041c02589a7csm6860512wmo.40.2024.04.29.06.00.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 Apr 2024 06:00:59 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 86da2ce4-0628-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1714395660; x=1715000460; darn=lists.xenproject.org; h=content-transfer-encoding:autocrypt:subject:from:cc:to :content-language:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=4WrhiGt4t2+rTjMGnuIXdmpTNrF6ykzuSNvQRaf3DNE=; b=BoTYmUtkqrqEgYHk13HdxzbS8A2GwsJ7i0tYOKJyMantMdIN1m9Gx3Dsix5uJr+1Ei h7XwLSNYPl/Xl0SZS7fKaK7iQZEZGgScKoam+LIvMdVaIOGcznz0QWqGn7sKN11rXH3q DciARUMDuIZzYxK6kJWm6trcK+/mTmMVhqmpiCNFxJffyHa/C14sxBHeva5DzPYc4yzz JwB19C5Nyfe1mvxhLSNCGn7kEBtFkcNzVBtuVOTMdQRsm8y6xjQWVGJM1yyEnrOS7oFf jmY9cQHzs5IQ83bAOZswWeNaa6lu+pcaNqPY1BtJNA8VYpBJRYnQh8kLERqaI2fDGTbS jRQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714395660; x=1715000460; h=content-transfer-encoding:autocrypt:subject:from:cc:to :content-language:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4WrhiGt4t2+rTjMGnuIXdmpTNrF6ykzuSNvQRaf3DNE=; b=dbE+WcGXTv5nBewST11lPS7q7G3PFiEibE1eTMKidEOsW0tK/GY+KXD0ozaSkG42qj 93FmX7iJ0FQrsAMldsfU6J1qRMIYLpEjxBfglFGp0j8mYvt/d0kJ9ZIRCo30CqlPHBF4 8uKJd4dX5TMaa4X0Rw0ft43JVGnap/hEy6xWec4txwcIpQbF+tnaMd0s+pKcgZRlWFcD O0wVy1px0v2ctSZHfOxv3faCkxJeSk0a41/xemRvL/dUcsQLoJvfcyAAMIK0WElu7CCL ZA6D/ARazK6hFRWURQL9fsY08ArQsikFvQxNLOmYkgonVxWkeGvQtMPx9Z5rNMK0Olqd agFQ== X-Gm-Message-State: AOJu0YyNyCsWtoSYRV4wmIIN906lzQl/LnU9B3xowJevJKFajYIFn467 lnv+39lNsSVDAzEWh1Abo9ooNR1bOHICPqoEOGzeQbONPlejIuOFdFPA+x6fsaXrxwiUe8o+Z9o = X-Google-Smtp-Source: AGHT+IEEkvz0YNMLjIXFgFvG6NZf0bgqboV82FTC1jpO/zGGT1hTsjQT7UX8VbwYkFQCNCaKDbixoA== X-Received: by 2002:a05:600c:3b16:b0:41c:1f4:9cbb with SMTP id m22-20020a05600c3b1600b0041c01f49cbbmr4546140wms.26.1714395659743; Mon, 29 Apr 2024 06:00:59 -0700 (PDT) Message-ID: Date: Mon, 29 Apr 2024 15:01:00 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , =?utf-8?q?Roger_Pau_Monn?= =?utf-8?q?=C3=A9?= , George Dunlap From: Jan Beulich Subject: [PATCH] revert "x86/mm: re-implement get_page_light() using an atomic increment" Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 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MlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL revert "x86/mm: re-implement get_page_light() using an atomic increment" This reverts commit c40bc0576dcc5acd4d7e22ef628eb4642f568533. That change aimed at eliminating an open-coded lock-like construct, which really isn't all that similar to, in particular, get_page(). The function always succeeds. Any remaining concern would want taking care of by placing block_lock_speculation() at the end of the function. Since the function is called only during page (de)validation, any possible performance concerns over such extra serialization could likely be addressed by pre-validating (e.g. via pinning) page tables. The fundamental issue with the change being reverted is that it detects bad state only after already having caused possible corruption. While the system is going to be halted in such an event, there is a time window during which the resulting incorrect state could be leveraged by a clever (in particular: fast enough) attacker. Signed-off-by: Jan Beulich Acked-by: Andrew Cooper Acked-by: Roger Pau Monné --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -2582,10 +2582,16 @@ bool get_page(struct page_info *page, const struct domain *domain) */ static void get_page_light(struct page_info *page) { - unsigned long old_pgc = arch_fetch_and_add(&page->count_info, 1); + unsigned long x, nx, y = page->count_info; - BUG_ON(!(old_pgc & PGC_count_mask)); /* Not allocated? */ - BUG_ON(!((old_pgc + 1) & PGC_count_mask)); /* Overflow? */ + do { + x = y; + nx = x + 1; + BUG_ON(!(x & PGC_count_mask)); /* Not allocated? */ + BUG_ON(!(nx & PGC_count_mask)); /* Overflow? */ + y = cmpxchg(&page->count_info, x, nx); + } + while ( unlikely(y != x) ); } static int validate_page(struct page_info *page, unsigned long type,