From patchwork Fri Apr 7 13:09:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 80798 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp275730vqo; Fri, 7 Apr 2023 06:12:40 -0700 (PDT) X-Google-Smtp-Source: AKy350Zd0kGaUpoOtvXwHDCLLh6dEwPrtA7f0pK5zVbmQi7kQqvtt+wLF+mvxnyjSieVdWY92M3K X-Received: by 2002:a05:6a20:1327:b0:d9:2827:b65a with SMTP id g39-20020a056a20132700b000d92827b65amr2542522pzh.5.1680873159916; Fri, 07 Apr 2023 06:12:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680873159; cv=none; d=google.com; s=arc-20160816; b=dSV+a91MD/iENJhYMPMAaK3d3+QuqQeUSrwVBxMDaXDXMHCpW86fYukRHzuQjuiHx7 tVjFuOpj5krzWH9JgrWpHRbNkiPqxVGYllNhoXz5Jy+UmGvRJeamn9R7WxuI+VJHl/TX mz4u18DEIyZETd9vIHzH5ArUeZr53O2k9ZaT1AFzsaHK6bRuZs2wKjp1GL+pWTi5EBeD K6VBRQNOWugp09xC+Hl2NvgbuqPOKDdBaQ1bATnElZvRAx8gCTgUFSXdqD6eR3UQ8c8b RvkjfJxMvU6EPyhDvoyzrBkeMLx3VmXUQfDTLovi5eHMWLy8VJmvY3A2c2e76eUaryJe Fkog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=JkVxDgCZzaUHhuVaWEGGlfuqQmfyNAV5VnpdsyyVXF4=; b=MuI+TPx/1pplIqD6ikSENzJp5zbqbpc5CEtkCh723x9Fs672JAZfyhuz80CQ/zXtVR /YnWuFkKvyaVPLfb0zHZO7cAKt3vRIT4diPaNCOSaAt0jHw3srfttqlWLVdKUIS0Mtvk hB/OCd7sVtZ9rWocyjtTZ7ioaNU6bYNYWR0TbN9jRvg0oNZHwOEp/3WI76CXI9a3wVk/ pWykTM7mU1t6Rm2G3Dwmuu0GiMjC5zUb8wBnryN2sWFWlvPjxRLffzHw1RMWqdXq5NHG yF9BYA3/uyOMS/c6uzonK9Nn805wRkce6ewfC2SzJkSizzve46BQSSX3miE5Qh+ddVL7 fqaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QhFAC6uW; dkim=neutral (no key) header.i=@linutronix.de header.b=3iaIQXeo; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h28-20020aa796dc000000b0062c1ea507cbsi3801271pfq.130.2023.04.07.06.12.21; Fri, 07 Apr 2023 06:12:39 -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=@linutronix.de header.s=2020 header.b=QhFAC6uW; dkim=neutral (no key) header.i=@linutronix.de header.b=3iaIQXeo; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240624AbjDGNJ6 (ORCPT + 99 others); Fri, 7 Apr 2023 09:09:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232213AbjDGNJ5 (ORCPT ); Fri, 7 Apr 2023 09:09:57 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2BB35590; Fri, 7 Apr 2023 06:09:55 -0700 (PDT) Date: Fri, 07 Apr 2023 13:09:52 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1680872993; h=from:from:sender:sender:reply-to: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=JkVxDgCZzaUHhuVaWEGGlfuqQmfyNAV5VnpdsyyVXF4=; b=QhFAC6uWupGXMnLQYOhBBBp30bECDy3o7IgZq7CWdbmrqzkMH3sDcv2eGNNQxUTavq5yFB c/DPc0Ak8enL8w0B6sev8g6kq2r0lxQDlgPFhSkzSe3/gzbQApbqmLuxfZGXOTLF14uELN ArNbRFHjoTAQ3AmyL0/5tEg4dzOzg8TsOVs6+TFWnfVqiJC/dFkVXiPQ2St4BhXduT+285 G0XlDtQQUMm/BEmxtZZwarT7/2OUttIARZgKxBsSlqKgCCD3SmJ4Kg6jg3SarLgXiDL+u4 S2V/F/Up7vH9g00ONrO6dAuC3/YVhp4ANYe2EIcJbVJlTYvCUceuEtAQsPSa9w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1680872993; h=from:from:sender:sender:reply-to: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=JkVxDgCZzaUHhuVaWEGGlfuqQmfyNAV5VnpdsyyVXF4=; b=3iaIQXeoUyME4d97qa1Y6BcsvrFyaBEDU2ElgIBjgap2VjSbY+wY2a8BkSdfiuh4RFDq3c bsvGqFZAN7XIQrBw== From: "tip-bot2 for Uros Bizjak" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/apic] x86/apic: Fix atomic update of offset in reserve_eilvt_offset() Cc: Uros Bizjak , "Borislav Petkov (AMD)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230227160917.107820-1-ubizjak@gmail.com> References: <20230227160917.107820-1-ubizjak@gmail.com> MIME-Version: 1.0 Message-ID: <168087299261.404.3541260516013039940.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762523254555693292?= X-GMAIL-MSGID: =?utf-8?q?1762523254555693292?= The following commit has been merged into the x86/apic branch of tip: Commit-ID: f96fb2df3eb31ede1b34b0521560967310267750 Gitweb: https://git.kernel.org/tip/f96fb2df3eb31ede1b34b0521560967310267750 Author: Uros Bizjak AuthorDate: Mon, 27 Feb 2023 17:09:17 +01:00 Committer: Borislav Petkov (AMD) CommitterDate: Fri, 07 Apr 2023 14:34:24 +02:00 x86/apic: Fix atomic update of offset in reserve_eilvt_offset() The detection of atomic update failure in reserve_eilvt_offset() is not correct. The value returned by atomic_cmpxchg() should be compared to the old value from the location to be updated. If these two are the same, then atomic update succeeded and "eilvt_offsets[offset]" location is updated to "new" in an atomic way. Otherwise, the atomic update failed and it should be retried with the value from "eilvt_offsets[offset]" - exactly what atomic_try_cmpxchg() does in a correct and more optimal way. Fixes: a68c439b1966c ("apic, x86: Check if EILVT APIC registers are available (AMD only)") Signed-off-by: Uros Bizjak Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/r/20230227160917.107820-1-ubizjak@gmail.com --- arch/x86/kernel/apic/apic.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c index 20d9a60..7705571 100644 --- a/arch/x86/kernel/apic/apic.c +++ b/arch/x86/kernel/apic/apic.c @@ -422,10 +422,9 @@ static unsigned int reserve_eilvt_offset(int offset, unsigned int new) if (vector && !eilvt_entry_is_changeable(vector, new)) /* may not change if vectors are different */ return rsvd; - rsvd = atomic_cmpxchg(&eilvt_offsets[offset], rsvd, new); - } while (rsvd != new); + } while (!atomic_try_cmpxchg(&eilvt_offsets[offset], &rsvd, new)); - rsvd &= ~APIC_EILVT_MASKED; + rsvd = new & ~APIC_EILVT_MASKED; if (rsvd && rsvd != vector) pr_info("LVT offset %d assigned for vector 0x%02x\n", offset, rsvd);