* [PATCH v10 0/2] s390: virtio: let arch validate VIRTIO features
@ 2020-08-31 9:09 Pierre Morel
2020-08-31 9:09 ` [PATCH v10 1/2] virtio: let arch advertise guest's memory access restrictions Pierre Morel
2020-08-31 9:09 ` [PATCH v10 2/2] s390: virtio: PV needs VIRTIO I/O device protection Pierre Morel
0 siblings, 2 replies; 4+ messages in thread
From: Pierre Morel @ 2020-08-31 9:09 UTC (permalink / raw)
To: linux-kernel
Cc: pasic, borntraeger, frankja, mst, jasowang, cohuck, kvm,
linux-s390, virtualization, thomas.lendacky, david, linuxram,
hca, gor
Hi all,
The goal of the series is to give a chance to the architecture
to validate VIRTIO device features.
The tests are back to virtio_finalize_features.
No more argument for the architecture callback which only reports
if the architecture needs guest memory access restrictions for
VIRTIO.
I renamed the callback to arch_has_restricted_virtio_memory_access,
and the config option to ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS.
Regards,
Pierre
Pierre Morel (2):
virtio: let arch advertise guest's memory access restrictions
s390: virtio: PV needs VIRTIO I/O device protection
arch/s390/Kconfig | 1 +
arch/s390/mm/init.c | 10 ++++++++++
drivers/virtio/Kconfig | 6 ++++++
drivers/virtio/virtio.c | 15 +++++++++++++++
include/linux/virtio_config.h | 9 +++++++++
5 files changed, 41 insertions(+)
--
2.25.1
Changelog
to v10:
- removed virtio_config.h unnecessary include
- wording
(Connie)
to v9:
- move virtio tests back to virtio_finalize_features
(Connie)
- remove virtio device argument
to v8:
- refactoring by using an optional callback
(Connie)
to v7:
- typo in warning message
(Connie)
to v6:
- rewording warning messages
(Connie, Halil)
to v5:
- return directly from S390 arch_validate_virtio_features()
when the guest is not protected.
(Connie)
- Somme rewording
(Connie, Michael)
- moved back code from arch/s390/ ...kernel/uv.c to ...mm/init.c
(Christian)
to v4:
- separate virtio and arch code
(Pierre)
- moved code from arch/s390/mm/init.c to arch/s390/kernel/uv.c
(as interpreted from Heiko's comment)
- moved validation inside the arch code
(Connie)
- moved the call to arch validation before VIRTIO_F_1 test
(Michael)
to v3:
- add warning
(Connie, Christian)
- add comment
(Connie)
- change hook name
(Halil, Connie)
to v2:
- put the test in virtio_finalize_features()
(Connie)
- put the test inside VIRTIO core
(Jason)
- pass a virtio device as parameter
(Halil)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v10 1/2] virtio: let arch advertise guest's memory access restrictions
2020-08-31 9:09 [PATCH v10 0/2] s390: virtio: let arch validate VIRTIO features Pierre Morel
@ 2020-08-31 9:09 ` Pierre Morel
2020-08-31 9:09 ` [PATCH v10 2/2] s390: virtio: PV needs VIRTIO I/O device protection Pierre Morel
1 sibling, 0 replies; 4+ messages in thread
From: Pierre Morel @ 2020-08-31 9:09 UTC (permalink / raw)
To: linux-kernel
Cc: pasic, borntraeger, frankja, mst, jasowang, cohuck, kvm,
linux-s390, virtualization, thomas.lendacky, david, linuxram,
hca, gor
An architecture may restrict host access to guest memory,
e.g. IBM s390 Secure Execution or AMD SEV.
Provide a new Kconfig entry the architecture can select,
CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS, when it provides
the arch_has_restricted_virtio_memory_access callback to advertise
to VIRTIO common code when the architecture restricts memory access
from the host.
The common code can then fail the probe for any device where
VIRTIO_F_IOMMU_PLATFORM is required, but not set.
Signed-off-by: Pierre Morel <pmorel@linux.ibm.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
---
drivers/virtio/Kconfig | 6 ++++++
drivers/virtio/virtio.c | 15 +++++++++++++++
include/linux/virtio_config.h | 9 +++++++++
3 files changed, 30 insertions(+)
diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig
index 5809e5f5b157..9cd1c267c143 100644
--- a/drivers/virtio/Kconfig
+++ b/drivers/virtio/Kconfig
@@ -6,6 +6,12 @@ config VIRTIO
bus, such as CONFIG_VIRTIO_PCI, CONFIG_VIRTIO_MMIO, CONFIG_RPMSG
or CONFIG_S390_GUEST.
+config ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS
+ bool
+ help
+ This option is selected if the architecture may need to enforce
+ VIRTIO_F_IOMMU_PLATFORM.
+
menuconfig VIRTIO_MENU
bool "Virtio drivers"
default y
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index a977e32a88f2..57ca41d77b09 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -176,6 +176,21 @@ int virtio_finalize_features(struct virtio_device *dev)
if (ret)
return ret;
+ ret = arch_has_restricted_virtio_memory_access();
+ if (ret) {
+ if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) {
+ dev_warn(&dev->dev,
+ "device must provide VIRTIO_F_VERSION_1\n");
+ return -ENODEV;
+ }
+
+ if (!virtio_has_feature(dev, VIRTIO_F_IOMMU_PLATFORM)) {
+ dev_warn(&dev->dev,
+ "device must provide VIRTIO_F_IOMMU_PLATFORM\n");
+ return -ENODEV;
+ }
+ }
+
if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1))
return 0;
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
index bb4cc4910750..e380664642b4 100644
--- a/include/linux/virtio_config.h
+++ b/include/linux/virtio_config.h
@@ -459,4 +459,13 @@ static inline void virtio_cwrite64(struct virtio_device *vdev,
_r; \
})
+#ifdef CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS
+int arch_has_restricted_virtio_memory_access(void);
+#else
+static inline int arch_has_restricted_virtio_memory_access(void)
+{
+ return 0;
+}
+#endif /* CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS */
+
#endif /* _LINUX_VIRTIO_CONFIG_H */
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v10 2/2] s390: virtio: PV needs VIRTIO I/O device protection
2020-08-31 9:09 [PATCH v10 0/2] s390: virtio: let arch validate VIRTIO features Pierre Morel
2020-08-31 9:09 ` [PATCH v10 1/2] virtio: let arch advertise guest's memory access restrictions Pierre Morel
@ 2020-08-31 9:09 ` Pierre Morel
2020-08-31 12:11 ` kernel test robot
1 sibling, 1 reply; 4+ messages in thread
From: Pierre Morel @ 2020-08-31 9:09 UTC (permalink / raw)
To: linux-kernel
Cc: pasic, borntraeger, frankja, mst, jasowang, cohuck, kvm,
linux-s390, virtualization, thomas.lendacky, david, linuxram,
hca, gor
If protected virtualization is active on s390, VIRTIO has only retricted
access to the guest memory.
Define CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS and export
arch_has_restricted_virtio_memory_access to advertize VIRTIO if that's
the case, preventing a host error on access attempt.
Signed-off-by: Pierre Morel <pmorel@linux.ibm.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
---
arch/s390/Kconfig | 1 +
arch/s390/mm/init.c | 10 ++++++++++
2 files changed, 11 insertions(+)
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 9cfd8de907cb..c12422c26389 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -820,6 +820,7 @@ menu "Virtualization"
config PROTECTED_VIRTUALIZATION_GUEST
def_bool n
prompt "Protected virtualization guest support"
+ select ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS
help
Select this option, if you want to be able to run this
kernel as a protected virtualization KVM guest.
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index 6dc7c3b60ef6..5f289ab1b0d2 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -161,6 +161,16 @@ bool force_dma_unencrypted(struct device *dev)
return is_prot_virt_guest();
}
+#ifdef CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS
+
+int arch_has_restricted_virtio_memory_access(void)
+{
+ return is_prot_virt_guest();
+}
+EXPORT_SYMBOL(arch_has_restricted_virtio_memory_access);
+
+#endif
+
/* protected virtualization */
static void pv_init(void)
{
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v10 2/2] s390: virtio: PV needs VIRTIO I/O device protection
2020-08-31 9:09 ` [PATCH v10 2/2] s390: virtio: PV needs VIRTIO I/O device protection Pierre Morel
@ 2020-08-31 12:11 ` kernel test robot
0 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2020-08-31 12:11 UTC (permalink / raw)
To: Pierre Morel, linux-kernel
Cc: kbuild-all, clang-built-linux, pasic, borntraeger, frankja, mst,
jasowang, cohuck, kvm, linux-s390, virtualization
[-- Attachment #1: Type: text/plain, Size: 9685 bytes --]
Hi Pierre,
I love your patch! Perhaps something to improve:
[auto build test WARNING on linux/master]
[cannot apply to s390/features linus/master v5.9-rc3 next-20200828]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Pierre-Morel/s390-virtio-let-arch-validate-VIRTIO-features/20200831-171552
base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git bcf876870b95592b52519ed4aafcf9d95999bc9c
config: s390-randconfig-r004-20200831 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project c10e63677f5d20f18010f8f68c631ddc97546f7d)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install s390 cross compiling tool for clang build
# apt-get install binutils-s390x-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=s390
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:119:21: note: expanded from macro '__swab32'
___constant_swab32(x) : \
^
include/uapi/linux/swab.h:20:12: note: expanded from macro '___constant_swab32'
(((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \
^
In file included from arch/s390/mm/init.c:20:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:22:
In file included from include/linux/writeback.h:14:
In file included from include/linux/blk-cgroup.h:23:
In file included from include/linux/blkdev.h:28:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:72:
include/asm-generic/io.h:490:45: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu(__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:34:59: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:119:21: note: expanded from macro '__swab32'
___constant_swab32(x) : \
^
include/uapi/linux/swab.h:21:12: note: expanded from macro '___constant_swab32'
(((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \
^
In file included from arch/s390/mm/init.c:20:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:22:
In file included from include/linux/writeback.h:14:
In file included from include/linux/blk-cgroup.h:23:
In file included from include/linux/blkdev.h:28:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:72:
include/asm-generic/io.h:490:45: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu(__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:34:59: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:119:21: note: expanded from macro '__swab32'
___constant_swab32(x) : \
^
include/uapi/linux/swab.h:22:12: note: expanded from macro '___constant_swab32'
(((__u32)(x) & (__u32)0xff000000UL) >> 24)))
^
In file included from arch/s390/mm/init.c:20:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:22:
In file included from include/linux/writeback.h:14:
In file included from include/linux/blk-cgroup.h:23:
In file included from include/linux/blkdev.h:28:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:72:
include/asm-generic/io.h:490:45: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu(__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:34:59: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:120:12: note: expanded from macro '__swab32'
__fswab32(x))
^
In file included from arch/s390/mm/init.c:20:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:22:
In file included from include/linux/writeback.h:14:
In file included from include/linux/blk-cgroup.h:23:
In file included from include/linux/blkdev.h:28:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:72:
include/asm-generic/io.h:501:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writeb(value, PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:511:46: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writew(cpu_to_le16(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:521:46: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writel(cpu_to_le32(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:609:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsb(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:617:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsw(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:625:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsl(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:634:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesb(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:643:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesw(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:652:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesl(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
>> arch/s390/mm/init.c:166:5: warning: no previous prototype for function 'arch_has_restricted_virtio_memory_access' [-Wmissing-prototypes]
int arch_has_restricted_virtio_memory_access(void)
^
arch/s390/mm/init.c:166:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
int arch_has_restricted_virtio_memory_access(void)
^
static
In file included from arch/s390/mm/init.c:11:
In file included from include/linux/signal.h:5:
In file included from include/linux/bug.h:5:
In file included from arch/s390/include/asm/bug.h:5:
In file included from include/linux/kernel.h:12:
In file included from include/linux/bitops.h:29:
arch/s390/include/asm/bitops.h:69:4: error: invalid operand in inline asm: 'oi $0,${1:b}'
"oi %0,%b1\n"
^
arch/s390/include/asm/bitops.h:69:4: error: invalid operand in inline asm: 'oi $0,${1:b}'
arch/s390/include/asm/bitops.h:69:4: error: invalid operand in inline asm: 'oi $0,${1:b}'
21 warnings and 3 errors generated.
# https://github.com/0day-ci/linux/commit/76e649717b36f092b03739629b7a036fcc383ee1
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Pierre-Morel/s390-virtio-let-arch-validate-VIRTIO-features/20200831-171552
git checkout 76e649717b36f092b03739629b7a036fcc383ee1
vim +/arch_has_restricted_virtio_memory_access +166 arch/s390/mm/init.c
165
> 166 int arch_has_restricted_virtio_memory_access(void)
167 {
168 return is_prot_virt_guest();
169 }
170 EXPORT_SYMBOL(arch_has_restricted_virtio_memory_access);
171
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 21587 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-08-31 12:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-31 9:09 [PATCH v10 0/2] s390: virtio: let arch validate VIRTIO features Pierre Morel
2020-08-31 9:09 ` [PATCH v10 1/2] virtio: let arch advertise guest's memory access restrictions Pierre Morel
2020-08-31 9:09 ` [PATCH v10 2/2] s390: virtio: PV needs VIRTIO I/O device protection Pierre Morel
2020-08-31 12:11 ` kernel test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).