From: Neeraj Upadhyay <Neeraj.Upadhyay@amd.com>
To: Borislav Petkov <bp@alien8.de>
Cc: linux-kernel@vger.kernel.org, tglx@linutronix.de,
mingo@redhat.com, dave.hansen@linux.intel.com,
Thomas.Lendacky@amd.com, nikunj@amd.com, Santosh.Shukla@amd.com,
Vasant.Hegde@amd.com, Suravee.Suthikulpanit@amd.com,
David.Kaplan@amd.com, x86@kernel.org, hpa@zytor.com,
peterz@infradead.org, seanjc@google.com, pbonzini@redhat.com,
kvm@vger.kernel.org
Subject: Re: [RFC 03/14] x86/apic: Populate .read()/.write() callbacks of Secure AVIC driver
Date: Thu, 7 Nov 2024 09:02:16 +0530 [thread overview]
Message-ID: <72878fd9-6b04-4336-a409-8118c4306171@amd.com> (raw)
In-Reply-To: <20241106181655.GYZyuyl0zDTTmlMKzz@fat_crate.local>
On 11/6/2024 11:46 PM, Borislav Petkov wrote:
> On Fri, Sep 13, 2024 at 05:06:54PM +0530, Neeraj Upadhyay wrote:
>> @@ -24,6 +25,108 @@ static int x2apic_savic_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
>> return x2apic_enabled() && cc_platform_has(CC_ATTR_SNP_SECURE_AVIC);
>> }
>>
>> +static inline u32 get_reg(char *page, int reg_off)
>
> Just "reg" like the other APICs.
>
Ok sure.
>> +static u32 x2apic_savic_read(u32 reg)
>> +{
>> + void *backing_page = this_cpu_read(apic_backing_page);
>> +
>> + switch (reg) {
>> + case APIC_LVTT:
>> + case APIC_TMICT:
>> + case APIC_TMCCT:
>> + case APIC_TDCR:
>> + case APIC_ID:
>> + case APIC_LVR:
>> + case APIC_TASKPRI:
>> + case APIC_ARBPRI:
>> + case APIC_PROCPRI:
>> + case APIC_LDR:
>> + case APIC_SPIV:
>> + case APIC_ESR:
>> + case APIC_ICR:
>> + case APIC_LVTTHMR:
>> + case APIC_LVTPC:
>> + case APIC_LVT0:
>> + case APIC_LVT1:
>> + case APIC_LVTERR:
>> + case APIC_EFEAT:
>> + case APIC_ECTRL:
>> + case APIC_SEOI:
>> + case APIC_IER:
>
> I'm sure those can be turned into ranges instead of enumerating every single
> APIC register...
>
Below are the offset of these, as per "Table 16-6. x2APIC Register" in
APM vol2:
#Reg #offset
APIC_LVTT - 0x320
APIC_TMICT - 0x380
APIC_TMCCT - 0x390
APIC_TDCR - 0x3E0
Above timer related registers are read from HV when we reach the end of this patch
series.
APIC_ID - 20h
APIC_LVR - 30h
APIC_TASKPRI - 80h
APIC_ARBPRI - 90h
APIC_PROCPRI - A0h
APIC_LDR - D0h
APIC_SPIV - F0h
APIC_ESR - 280h
APIC_ICR - 300h
APIC_LVTTHMR - 330h
APIC_LVTPC - 340h
APIC_LVT0 - 350h
APIC_LVT1 - 360h
APIC_LVTERR - 370h
APIC_EFEAT - 0x400h
APIC_ECTRL - 0x410h
APIC_SEOI - 0x420h
APIC_IER - 0x480h
These are few registers like part of LVT (APIC_LVTTHMR ... APIC_LVTERR) ,
priority (APIC_TASKPRI ... APIC_PROCPRI), extended APIC
(APIC_EFEAT ... APIC_ECTRL) which can be grouped.
Intention of doing per reg is to be explicit about which registers
are accessed from backing page, which from hv and which are not allowed
access. As access (and their perms) are per-reg and not range-based, this
made sense to me. Also, if ranges are used, I think 16-byte aligned
checks are needed for the range. If using ranges looks more logical grouping
here, I can update it as per the above range groupings.
>> + case APIC_EILVTn(0) ... APIC_EILVTn(3):
>
> Like here.
>
As this case is for EILVT register range, these registers were grouped.
(I need to add a 16-byte alignment check here).
>> + return get_reg(backing_page, reg);
>> + case APIC_ISR ... APIC_ISR + 0x70:
>> + case APIC_TMR ... APIC_TMR + 0x70:
>> + WARN_ONCE(!IS_ALIGNED(reg, 16), "Reg offset %#x not aligned at 16 bytes", reg);
>
> What's the point of a WARN...
>
>> + return get_reg(backing_page, reg);
>
> ... and then allowing the register access anyway?
>
I will skip access for non-aligned case.
>> + /* IRR and ALLOWED_IRR offset range */
>> + case APIC_IRR ... APIC_IRR + 0x74:
>> + /*
>> + * Either aligned at 16 bytes for valid IRR reg offset or a
>> + * valid Secure AVIC ALLOWED_IRR offset.
>> + */
>> + WARN_ONCE(!(IS_ALIGNED(reg, 16) || IS_ALIGNED(reg - SAVIC_ALLOWED_IRR_OFFSET, 16)),
>> + "Misaligned IRR/ALLOWED_IRR reg offset %#x", reg);
>> + return get_reg(backing_page, reg);
>
> Ditto.
>
> And below too.
>
Same reply as above.
- Neeraj
>> + default:
>> + pr_err("Permission denied: read of Secure AVIC reg offset %#x\n", reg);
>> + return 0;
>> + }
>> +}
>> +
next prev parent reply other threads:[~2024-11-07 3:32 UTC|newest]
Thread overview: 81+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-13 11:36 [RFC 00/14] AMD: Add Secure AVIC Guest Support Neeraj Upadhyay
2024-09-13 11:36 ` [RFC 01/14] x86/apic: Add new driver for Secure AVIC Neeraj Upadhyay
2024-10-08 19:15 ` Borislav Petkov
2024-10-09 1:56 ` Neeraj Upadhyay
2024-10-09 5:23 ` Borislav Petkov
2024-10-09 6:01 ` Neeraj Upadhyay
2024-10-09 10:38 ` Borislav Petkov
2024-10-09 11:00 ` Neeraj Upadhyay
2024-10-09 11:02 ` Borislav Petkov
2024-10-09 12:38 ` Neeraj Upadhyay
2024-10-09 13:15 ` Tom Lendacky
2024-10-09 13:50 ` Neeraj Upadhyay
2024-10-09 10:10 ` Kirill A. Shutemov
2024-10-09 10:42 ` Borislav Petkov
2024-10-09 11:03 ` Kirill A. Shutemov
2024-10-09 11:22 ` Borislav Petkov
2024-10-09 12:12 ` Kirill A. Shutemov
2024-10-09 13:53 ` Borislav Petkov
2024-10-11 7:29 ` Kirill A. Shutemov
2024-11-18 21:45 ` Melody (Huibo) Wang
2024-11-21 5:05 ` Neeraj Upadhyay
2024-11-21 5:41 ` Borislav Petkov
2024-11-21 8:03 ` Neeraj Upadhyay
2024-11-21 10:53 ` Borislav Petkov
2024-11-25 7:21 ` Neeraj Upadhyay
2024-11-25 10:08 ` Borislav Petkov
2024-11-25 11:16 ` Neeraj Upadhyay
2024-09-13 11:36 ` [RFC 02/14] x86/apic: Initialize Secure AVIC APIC backing page Neeraj Upadhyay
2024-10-09 15:27 ` Dave Hansen
2024-10-09 16:31 ` Neeraj Upadhyay
2024-10-09 17:03 ` Dave Hansen
2024-10-09 17:52 ` Neeraj Upadhyay
2024-10-23 16:30 ` Borislav Petkov
2024-10-24 4:01 ` Neeraj Upadhyay
2024-10-24 11:49 ` Borislav Petkov
2024-10-24 12:31 ` Neeraj Upadhyay
2024-10-24 12:59 ` Borislav Petkov
2024-10-23 16:36 ` Borislav Petkov
2024-10-24 3:24 ` Neeraj Upadhyay
2024-09-13 11:36 ` [RFC 03/14] x86/apic: Populate .read()/.write() callbacks of Secure AVIC driver Neeraj Upadhyay
2024-11-06 18:16 ` Borislav Petkov
2024-11-07 3:32 ` Neeraj Upadhyay [this message]
2024-11-07 14:28 ` Borislav Petkov
2024-11-08 8:59 ` Neeraj Upadhyay
2024-11-08 10:48 ` Borislav Petkov
2024-11-08 16:14 ` Neeraj Upadhyay
2024-11-06 19:20 ` Melody (Huibo) Wang
2024-11-07 3:33 ` Neeraj Upadhyay
2024-09-13 11:36 ` [RFC 04/14] x86/apic: Initialize APIC backing page for Secure AVIC Neeraj Upadhyay
2024-11-07 15:28 ` Borislav Petkov
2024-11-08 18:08 ` Neeraj Upadhyay
2024-11-09 16:27 ` Borislav Petkov
2024-11-09 16:51 ` Neeraj Upadhyay
2024-11-11 22:43 ` [sos-linux-ext-patches] " Melody (Huibo) Wang
2024-11-12 3:01 ` Neeraj Upadhyay
2024-09-13 11:36 ` [RFC 05/14] x86/apic: Initialize APIC ID " Neeraj Upadhyay
2024-11-09 20:13 ` [sos-linux-ext-patches] " Melody (Huibo) Wang
2024-11-10 3:55 ` Neeraj Upadhyay
2024-11-10 12:12 ` Borislav Petkov
2024-11-10 15:22 ` Neeraj Upadhyay
2024-11-10 16:34 ` Borislav Petkov
2024-11-11 3:45 ` Neeraj Upadhyay
2024-09-13 11:36 ` [RFC 06/14] x86/apic: Add update_vector callback " Neeraj Upadhyay
2024-09-13 11:36 ` [RFC 07/14] x86/apic: Add support to send IPI " Neeraj Upadhyay
2024-09-13 11:36 ` [RFC 08/14] x86/apic: Support LAPIC timer " Neeraj Upadhyay
2024-09-13 11:37 ` [RFC 09/14] x86/sev: Initialize VGIF for secondary VCPUs " Neeraj Upadhyay
2024-09-13 11:37 ` [RFC 10/14] x86/apic: Add support to send NMI IPI " Neeraj Upadhyay
2024-09-13 11:37 ` [RFC 11/14] x86/apic: Allow NMI to be injected from hypervisor " Neeraj Upadhyay
2024-09-13 11:37 ` [RFC 12/14] x86/sev: Enable NMI support " Neeraj Upadhyay
2024-09-13 11:37 ` [RFC 13/14] x86/apic: Enable Secure AVIC in Control MSR Neeraj Upadhyay
2024-09-13 11:37 ` [RFC 14/14] x86/sev: Indicate SEV-SNP guest supports Secure AVIC Neeraj Upadhyay
2024-10-17 8:23 ` [RFC 00/14] AMD: Add Secure AVIC Guest Support Kirill A. Shutemov
2024-10-18 2:33 ` Neeraj Upadhyay
2024-10-18 7:54 ` Kirill A. Shutemov
2024-10-29 9:47 ` Borislav Petkov
2024-10-29 10:24 ` Neeraj Upadhyay
2024-10-29 10:54 ` Borislav Petkov
2024-10-29 11:51 ` Kirill A. Shutemov
2024-10-29 12:15 ` Neeraj Upadhyay
2024-10-29 14:36 ` Kirill A. Shutemov
2024-10-29 15:28 ` Neeraj Upadhyay
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=72878fd9-6b04-4336-a409-8118c4306171@amd.com \
--to=neeraj.upadhyay@amd.com \
--cc=David.Kaplan@amd.com \
--cc=Santosh.Shukla@amd.com \
--cc=Suravee.Suthikulpanit@amd.com \
--cc=Thomas.Lendacky@amd.com \
--cc=Vasant.Hegde@amd.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=nikunj@amd.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®