From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anup Patel Date: Thu, 21 Mar 2024 14:20:40 +0530 Subject: [PATCH 1/2] RISC-V: KVM: Fix APLIC setipnum_le/be write emulation In-Reply-To: <20240321085041.1955293-1-apatel@ventanamicro.com> References: <20240321085041.1955293-1-apatel@ventanamicro.com> Message-ID: <20240321085041.1955293-2-apatel@ventanamicro.com> List-Id: To: kvm-riscv@lists.infradead.org MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit The writes to setipnum_le/be register for APLIC in MSI-mode have special consideration for level-triggered interrupts as-per the section "4.9.2 Special consideration for level-sensitive interrupt sources" of the RISC-V AIA specification. Particularly, the below text from the RISC-V AIA specification defines the behaviour of writes to setipnum_le/be register for level-triggered interrupts: "A second option is for the interrupt service routine to write the APLIC?s source identity number for the interrupt to the domain?s setipnum register just before exiting. This will cause the interrupt?s pending bit to be set to one again if the source is still asserting an interrupt, but not if the source is not asserting an interrupt." Fix setipnum_le/be write emulation for in-kernel APLIC by implementing the above behaviour in aplic_write_pending() function. Cc: stable at vger.kernel.org Fixes: 74967aa208e2 ("RISC-V: KVM: Add in-kernel emulation of AIA APLIC") Signed-off-by: Anup Patel --- arch/riscv/kvm/aia_aplic.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kvm/aia_aplic.c b/arch/riscv/kvm/aia_aplic.c index 39e72aa016a4..5e842b92dc46 100644 --- a/arch/riscv/kvm/aia_aplic.c +++ b/arch/riscv/kvm/aia_aplic.c @@ -137,11 +137,21 @@ static void aplic_write_pending(struct aplic *aplic, u32 irq, bool pending) raw_spin_lock_irqsave(&irqd->lock, flags); sm = irqd->sourcecfg & APLIC_SOURCECFG_SM_MASK; - if (!pending && - ((sm == APLIC_SOURCECFG_SM_LEVEL_HIGH) || - (sm == APLIC_SOURCECFG_SM_LEVEL_LOW))) + if (sm == APLIC_SOURCECFG_SM_INACTIVE) goto skip_write_pending; + if (sm == APLIC_SOURCECFG_SM_LEVEL_HIGH || + sm == APLIC_SOURCECFG_SM_LEVEL_LOW) { + if (!pending) + goto skip_write_pending; + if ((irqd->state & APLIC_IRQ_STATE_INPUT) && + sm == APLIC_SOURCECFG_SM_LEVEL_LOW) + goto skip_write_pending; + if (!(irqd->state & APLIC_IRQ_STATE_INPUT) && + sm == APLIC_SOURCECFG_SM_LEVEL_HIGH) + goto skip_write_pending; + } + if (pending) irqd->state |= APLIC_IRQ_STATE_PENDING; else -- 2.34.1 From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 57426C54E58 for ; Thu, 21 Mar 2024 08:51:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UmCyhFyFTiTS3mDoz5a1Hb0F9astkNVDYqBfLrghtqg=; b=I+7LYIxStyAgD6 Fsst9i1kA97pJ8HpZ4dfuVRghGHSRalj9tNrmQTmrxea3Yhs1tGnwccxNvZXabSZnjb7MZjf8p2ew xAchpOcm//tOc69VaR2P2sd2o6/Q9V/5BauiZumqa5fo7IrPqj1OyY8yNoq1QVK3iOT0sOgRgYRzW ZJZs2d4jqdMtxkVGkD1xggdd2t/m3CEcYG+Tzf1QH4xeKiPreZzJGUueAk3aexo0H0+1EDMlYINMI yGBGU9QEXK5PgSsT1mUPVSTyh61ziT0OKI1RjGUqfevuXVv7KrVVDse6zz9jnvNKaAAjfBSCVGp5e gWM6FJUxee74WC3i0/1g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rnE8f-00000002OKW-0X9u; Thu, 21 Mar 2024 08:51:05 +0000 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rnE8b-00000002OIJ-3eqB for linux-riscv@lists.infradead.org; Thu, 21 Mar 2024 08:51:03 +0000 Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-3c38f4e18eeso498109b6e.1 for ; Thu, 21 Mar 2024 01:51:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1711011060; x=1711615860; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pb2DImA394Xn1GF25dwWbz9ebhgojzvFgrEv+j58JQY=; b=eM2LREY++IXxS42wegmfir2ww+iNjGQ9rhzrPEz8vhr4mlr5Dg9nJ8fEBX8HoLzegp 9Er1fjNVjUv65B+dVM0HF6S8m8BGk330I6xYHlF8w5LTWR3z+pgzRVeOXxQLe8tAWUkh AcAj4gdiclSBVwWx/Wuh2ZAnqxm8AURJdnsIdt9WhO9vEM1GVbbyG9QYmpXAziH1RaTO JpDU717dvWuWpEDPVdUQOJbNo0ZJ554d0aSrxZpopkpImQI4jWiO4Iff9VQbyZ7PEbLB RcAzJCQgCUtYTVnipQfKC+RfNESnwT2jZywkWGEZrdN30b1h7Xz6Ku7z5icOMtYbZv27 f31g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711011060; x=1711615860; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pb2DImA394Xn1GF25dwWbz9ebhgojzvFgrEv+j58JQY=; b=Tts4jS2I+r7vMl4ZEOmbR9O1d4qCua8NGvQqxaeQdMMPf/vtjxtMNv/83KsGtoum+1 8rdKbYoM+IbGjB4wCOLKjByjsajPfF8PYmhNoQCRg7y6ztp2PHnIk2AV0AnVM8Q0bPrf RKE7h0KWmBpRMIX5dN9EW4jtK/O8Ex0dun81X02yKVfgFHlHaN1MIONBLqShb8gHvdN3 bL5kGGxx22mzRJSQHSNuavT0qfMFg5l6wQMYq6XpGVzbaKbn9ElfDgaCdAFBcC1SKccF k2nibZh3wOH5FfuK8BtzwP0gMppI8PvbZrFbOdbQ7d3VRHHZ3+bH1y6IOwxZvKnDWE2S 2kLg== X-Forwarded-Encrypted: i=1; AJvYcCXbkKI6Cl9CrbemXnUP0iizOcNDA4qzOEK7GuW+XkAdKWbhUuv0PgK1q5mKaz5l4+nwU9TmRLD+XT15oCjQy4sQh4YMHwTRfkuHANc3XyE9 X-Gm-Message-State: AOJu0YxvZTuRSUDQCDFy+L0T2/V+YpZJ4MgTV/wJWpIJjf+/W2dSHHws +i2XyKPZzBrUOmvF3EiN1vlX3evvbK5N129npbeJwvY0sCXZ2x5Xkjqvb6mhhCE= X-Google-Smtp-Source: AGHT+IFm6Yj6dZwM/TRCsKt+MMBPFQPRbWez6YSGqm2WUAe87j/A2qKzPB8fe5tq8WbjG6fC4RnUTA== X-Received: by 2002:a05:6808:f90:b0:3c3:a696:c7e1 with SMTP id o16-20020a0568080f9000b003c3a696c7e1mr3806907oiw.3.1711011060344; Thu, 21 Mar 2024 01:51:00 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id x3-20020a544003000000b003c3753dd869sm2275409oie.58.2024.03.21.01.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 01:50:59 -0700 (PDT) From: Anup Patel To: Paolo Bonzini , Atish Patra Cc: Palmer Dabbelt , Paul Walmsley , Andrew Jones , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel , stable@vger.kernel.org Subject: [PATCH 1/2] RISC-V: KVM: Fix APLIC setipnum_le/be write emulation Date: Thu, 21 Mar 2024 14:20:40 +0530 Message-Id: <20240321085041.1955293-2-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240321085041.1955293-1-apatel@ventanamicro.com> References: <20240321085041.1955293-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240321_015101_958752_5329E2F9 X-CRM114-Status: GOOD ( 14.04 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org VGhlIHdyaXRlcyB0byBzZXRpcG51bV9sZS9iZSByZWdpc3RlciBmb3IgQVBMSUMgaW4gTVNJLW1v ZGUgaGF2ZSBzcGVjaWFsCmNvbnNpZGVyYXRpb24gZm9yIGxldmVsLXRyaWdnZXJlZCBpbnRlcnJ1 cHRzIGFzLXBlciB0aGUgc2VjdGlvbiAiNC45LjIKU3BlY2lhbCBjb25zaWRlcmF0aW9uIGZvciBs ZXZlbC1zZW5zaXRpdmUgaW50ZXJydXB0IHNvdXJjZXMiIG9mIHRoZSBSSVNDLVYKQUlBIHNwZWNp ZmljYXRpb24uCgpQYXJ0aWN1bGFybHksIHRoZSBiZWxvdyB0ZXh0IGZyb20gdGhlIF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zbSA9PSBBUExJQ19T T1VSQ0VDRkdfU01fTEVWRUxfTE9XKQorCQkJZ290byBza2lwX3dyaXRlX3BlbmRpbmc7CisJCWlm ICghKGlycWQtPnN0YXRlICYgQVBMSUNfSVJRX1NUQVRFX0lOUFVUKSAmJgorCQkgICAgc20gPT0g QVBMSUNfU09VUkNFQ0ZHX1NNX0xFVkVMX0hJR0gpCisJCQlnb3RvIHNraXBfd3JpdGVfcGVuZGlu ZzsKKwl9CisKIAlpZiAocGVuZGluZykKIAkJaXJxZC0+c3RhdGUgfD0gQVBMSUNfSVJRX1NUQVRF X1BFTkRJTkc7CiAJZWxzZQotLSAKMi4zNC4xCgoKX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX18KbGludXgtcmlzY3YgbWFpbGluZyBsaXN0CmxpbnV4LXJpc2N2 QGxpc3RzLmluZnJhZGVhZC5vcmcKaHR0cDovL2xpc3RzLmluZnJhZGVhZC5vcmcvbWFpbG1hbi9s aXN0aW5mby9saW51eC1yaXNjdgo= From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f175.google.com (mail-oi1-f175.google.com [209.85.167.175]) (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 7DA7741C73 for ; Thu, 21 Mar 2024 08:51:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711011063; cv=none; b=gnBjeL6AGoo3HNVQYcMvf86CBekHEk41GqTARK5lb3xcxAuACtqMFVKRb2fiCAlGJb1ywd9tGhKYIBOSmyOb0mn5FDRF4JcZv8yjzI0MCdTB+BcnqXEn7AHT2BT4wdcj1H7AXPJ/egO88yate/bqBGyowxTkvqdCp2Zg1iuNnuI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711011063; c=relaxed/simple; bh=b0D5UA4UkNTQ3hrb1awYFHUtTZYLtdiN4O7EFOEvags=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=VzUMvOng7ld6xLucGygXvjsTX8qJSXHq1lcBZTdfjE4bwoR1c+EnejZqgXMpJ2sFC1MeTryI4G91CSBU4Wag1U/fLIcTE8NK7+dAGL3wg0DeK9Ggm6CQ2Wd3L9TTM8V+tSn4AdGa6MJLAq/xnZI1NXZxNXLecq1y0Oz7rSlSG88= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=LDZEiYRz; arc=none smtp.client-ip=209.85.167.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="LDZEiYRz" Received: by mail-oi1-f175.google.com with SMTP id 5614622812f47-3c3acf4b0e1so232081b6e.0 for ; Thu, 21 Mar 2024 01:51:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1711011060; x=1711615860; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pb2DImA394Xn1GF25dwWbz9ebhgojzvFgrEv+j58JQY=; b=LDZEiYRzupwHf9CELWDC7TlZ2QtUQHw0qIvkW35avc9BQyKfqazv32MorD1fpgAYBc /nu+IvHj1GItxG8GXXF9D7PMIzuqwQC8phEON/0cxxRShKf/3yPxQFszywjqfsyZ+QsH aJZdLigMG7Dxp144TPTolkeLmmIm+VsPtk1zPl40RKRQJ2GIrHydB25g1vDEx6Bst8Ia LeEsFcJVTKzdVlNfEya/AtJws68++FzKE2OqOMnS8Zj6hsIWAApo+u/c5pBDpAN+reVU AgSQ54MAWQNAchrQM0U/sAR3OkUc86JRRhE4zXSTxDfjnZkBRyNSlx8O+tXVqtfLjKJ5 azPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711011060; x=1711615860; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pb2DImA394Xn1GF25dwWbz9ebhgojzvFgrEv+j58JQY=; b=TWMlvbR/mPb71nfpA1KTi8B3CNbdZLYDbtBeHtb5kcDT0F7eC7f+tWfJDOhrbPEi4Z lvfTa5+NrUTBQpPs7DCU0a/S8QL1M+7mUvmvYeN914YryxLsvD030msCNkW0FJZeZ1pM 0wR6AWVdOYGa/o2IKOTE3ClhEniF/785U9g89ANDSnQgl8EhzlZAqLoOMCg9PfdwtNNq a8ONpifDQR/sI2L11isfiFQIxPIqxrGAOHsfajhKy+9LFxUERmRrUyni1HS9ot60wVwq FMG7T2IJn1yvnBVTbYAK18rrSnGJ8RWGv0tYO9lmlH84/sXeFXQyaOFea8AiJzf9bAzW h2Iw== X-Forwarded-Encrypted: i=1; AJvYcCUQM8zMSpExtDUILDyMsrMI9aG3OSkL90OJXkVFNAtRFF5usyhaSfGG1YbswdWbtPoYQeu37alrDExbFIQ8n1vLNgdoxIDB X-Gm-Message-State: AOJu0Ywu8g7mna+edutsBgckwZUQVpidThPw86mdh3/4eZybP60AS5Uy ufpmQm/bQtP6B3dY9sEh2rp/HFfslVveRZ5xe/PV7XLEVSO9pa2Ffa9uFucAgIo= X-Google-Smtp-Source: AGHT+IFm6Yj6dZwM/TRCsKt+MMBPFQPRbWez6YSGqm2WUAe87j/A2qKzPB8fe5tq8WbjG6fC4RnUTA== X-Received: by 2002:a05:6808:f90:b0:3c3:a696:c7e1 with SMTP id o16-20020a0568080f9000b003c3a696c7e1mr3806907oiw.3.1711011060344; Thu, 21 Mar 2024 01:51:00 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id x3-20020a544003000000b003c3753dd869sm2275409oie.58.2024.03.21.01.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 01:50:59 -0700 (PDT) From: Anup Patel To: Paolo Bonzini , Atish Patra Cc: Palmer Dabbelt , Paul Walmsley , Andrew Jones , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel , stable@vger.kernel.org Subject: [PATCH 1/2] RISC-V: KVM: Fix APLIC setipnum_le/be write emulation Date: Thu, 21 Mar 2024 14:20:40 +0530 Message-Id: <20240321085041.1955293-2-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240321085041.1955293-1-apatel@ventanamicro.com> References: <20240321085041.1955293-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The writes to setipnum_le/be register for APLIC in MSI-mode have special consideration for level-triggered interrupts as-per the section "4.9.2 Special consideration for level-sensitive interrupt sources" of the RISC-V AIA specification. Particularly, the below text from the RISC-V AIA specification defines the behaviour of writes to setipnum_le/be register for level-triggered interrupts: "A second option is for the interrupt service routine to write the APLIC’s source identity number for the interrupt to the domain’s setipnum register just before exiting. This will cause the interrupt’s pending bit to be set to one again if the source is still asserting an interrupt, but not if the source is not asserting an interrupt." Fix setipnum_le/be write emulation for in-kernel APLIC by implementing the above behaviour in aplic_write_pending() function. Cc: stable@vger.kernel.org Fixes: 74967aa208e2 ("RISC-V: KVM: Add in-kernel emulation of AIA APLIC") Signed-off-by: Anup Patel --- arch/riscv/kvm/aia_aplic.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kvm/aia_aplic.c b/arch/riscv/kvm/aia_aplic.c index 39e72aa016a4..5e842b92dc46 100644 --- a/arch/riscv/kvm/aia_aplic.c +++ b/arch/riscv/kvm/aia_aplic.c @@ -137,11 +137,21 @@ static void aplic_write_pending(struct aplic *aplic, u32 irq, bool pending) raw_spin_lock_irqsave(&irqd->lock, flags); sm = irqd->sourcecfg & APLIC_SOURCECFG_SM_MASK; - if (!pending && - ((sm == APLIC_SOURCECFG_SM_LEVEL_HIGH) || - (sm == APLIC_SOURCECFG_SM_LEVEL_LOW))) + if (sm == APLIC_SOURCECFG_SM_INACTIVE) goto skip_write_pending; + if (sm == APLIC_SOURCECFG_SM_LEVEL_HIGH || + sm == APLIC_SOURCECFG_SM_LEVEL_LOW) { + if (!pending) + goto skip_write_pending; + if ((irqd->state & APLIC_IRQ_STATE_INPUT) && + sm == APLIC_SOURCECFG_SM_LEVEL_LOW) + goto skip_write_pending; + if (!(irqd->state & APLIC_IRQ_STATE_INPUT) && + sm == APLIC_SOURCECFG_SM_LEVEL_HIGH) + goto skip_write_pending; + } + if (pending) irqd->state |= APLIC_IRQ_STATE_PENDING; else -- 2.34.1