public inbox for linux-s390@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] s390: ipl: fix physical-virtual confusion for diag308
@ 2023-03-10 12:22 Nico Boehr
  2023-03-10 12:34 ` Alexander Gordeev
  0 siblings, 1 reply; 7+ messages in thread
From: Nico Boehr @ 2023-03-10 12:22 UTC (permalink / raw)
  To: hca, gor, agordeev, borntraeger, svens; +Cc: linux-s390, mhartmay

Diag 308 subcodes expect a physical address as their parameter.

This currently is not a bug, but in the future physical and virtual
addresses might differ.

Fix the confusion by doing a virtual-to-physical conversion in the
exported diag308() and leave the assembly wrapper __diag308() alone.

Note that several callers pass NULL as addr, this is fine since
virt_to_phys(0) == 0.

Suggested-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 arch/s390/kernel/ipl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/s390/kernel/ipl.c b/arch/s390/kernel/ipl.c
index 5f0f5c86963a..5611ba8f68b9 100644
--- a/arch/s390/kernel/ipl.c
+++ b/arch/s390/kernel/ipl.c
@@ -176,7 +176,7 @@ static bool reipl_fcp_clear;
 static bool reipl_ccw_clear;
 static bool reipl_eckd_clear;
 
-static inline int __diag308(unsigned long subcode, void *addr)
+static inline int __diag308(unsigned long subcode, u64 addr)
 {
 	union register_pair r1;
 
@@ -195,7 +195,7 @@ static inline int __diag308(unsigned long subcode, void *addr)
 int diag308(unsigned long subcode, void *addr)
 {
 	diag_stat_inc(DIAG_STAT_X308);
-	return __diag308(subcode, addr);
+	return __diag308(subcode, virt_to_phys(addr));
 }
 EXPORT_SYMBOL_GPL(diag308);
 
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v1] s390: ipl: fix physical-virtual confusion for diag308
  2023-03-10 12:22 [PATCH v1] s390: ipl: fix physical-virtual confusion for diag308 Nico Boehr
@ 2023-03-10 12:34 ` Alexander Gordeev
  2023-03-10 12:42   ` Alexander Gordeev
  0 siblings, 1 reply; 7+ messages in thread
From: Alexander Gordeev @ 2023-03-10 12:34 UTC (permalink / raw)
  To: Nico Boehr; +Cc: hca, gor, borntraeger, svens, linux-s390, mhartmay

On Fri, Mar 10, 2023 at 01:22:04PM +0100, Nico Boehr wrote:
> Diag 308 subcodes expect a physical address as their parameter.
> 
> This currently is not a bug, but in the future physical and virtual
> addresses might differ.
> 
> Fix the confusion by doing a virtual-to-physical conversion in the
> exported diag308() and leave the assembly wrapper __diag308() alone.
> 
> Note that several callers pass NULL as addr, this is fine since
> virt_to_phys(0) == 0.
> 
> Suggested-by: Marc Hartmayer <mhartmay@linux.ibm.com>
> Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
> ---
>  arch/s390/kernel/ipl.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/s390/kernel/ipl.c b/arch/s390/kernel/ipl.c
> index 5f0f5c86963a..5611ba8f68b9 100644
> --- a/arch/s390/kernel/ipl.c
> +++ b/arch/s390/kernel/ipl.c
> @@ -176,7 +176,7 @@ static bool reipl_fcp_clear;
>  static bool reipl_ccw_clear;
>  static bool reipl_eckd_clear;
>  
> -static inline int __diag308(unsigned long subcode, void *addr)
> +static inline int __diag308(unsigned long subcode, u64 addr)
>  {
>  	union register_pair r1;
>  
> @@ -195,7 +195,7 @@ static inline int __diag308(unsigned long subcode, void *addr)
>  int diag308(unsigned long subcode, void *addr)
>  {
>  	diag_stat_inc(DIAG_STAT_X308);
> -	return __diag308(subcode, addr);
> +	return __diag308(subcode, virt_to_phys(addr));
>  }
>  EXPORT_SYMBOL_GPL(diag308);

Please note diag308() is called with NULL a lot.
I think a proper fix would be like this:

diff --git a/arch/s390/kernel/ipl.c b/arch/s390/kernel/ipl.c
index 0f91cd401eef..43de939b7af1 100644
--- a/arch/s390/kernel/ipl.c
+++ b/arch/s390/kernel/ipl.c
@@ -176,11 +176,11 @@ static bool reipl_fcp_clear;
 static bool reipl_ccw_clear;
 static bool reipl_eckd_clear;
 
-static inline int __diag308(unsigned long subcode, void *addr)
+static inline int __diag308(unsigned long subcode, unsigned long addr)
 {
 	union register_pair r1;
 
-	r1.even = (unsigned long) addr;
+	r1.even = addr;
 	r1.odd	= 0;
 	asm volatile(
 		"	diag	%[r1],%[subcode],0x308\n"
@@ -195,7 +195,7 @@ static inline int __diag308(unsigned long subcode, void *addr)
 int diag308(unsigned long subcode, void *addr)
 {
 	diag_stat_inc(DIAG_STAT_X308);
-	return __diag308(subcode, addr);
+	return __diag308(subcode, addr ? virt_to_phys(addr) : 0);
 }
 EXPORT_SYMBOL_GPL(diag308);

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v1] s390: ipl: fix physical-virtual confusion for diag308
  2023-03-10 12:34 ` Alexander Gordeev
@ 2023-03-10 12:42   ` Alexander Gordeev
  2023-03-10 13:05     ` Nico Boehr
  2023-03-10 13:20     ` Christian Borntraeger
  0 siblings, 2 replies; 7+ messages in thread
From: Alexander Gordeev @ 2023-03-10 12:42 UTC (permalink / raw)
  To: Nico Boehr; +Cc: hca, gor, borntraeger, svens, linux-s390, mhartmay

On Fri, Mar 10, 2023 at 01:34:27PM +0100, Alexander Gordeev wrote:
> > Note that several callers pass NULL as addr, this is fine since
> > virt_to_phys(0) == 0.

Missed that.

Are you sure? Quickly checked ppc64, x86 and arm64 - they do not 
seem adhere virt_to_phys(0) == 0, nor the VR kernel (so far).

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1] s390: ipl: fix physical-virtual confusion for diag308
  2023-03-10 12:42   ` Alexander Gordeev
@ 2023-03-10 13:05     ` Nico Boehr
  2023-03-10 13:20     ` Christian Borntraeger
  1 sibling, 0 replies; 7+ messages in thread
From: Nico Boehr @ 2023-03-10 13:05 UTC (permalink / raw)
  To: Alexander Gordeev; +Cc: hca, gor, borntraeger, svens, linux-s390, mhartmay

Quoting Alexander Gordeev (2023-03-10 13:42:47)
> On Fri, Mar 10, 2023 at 01:34:27PM +0100, Alexander Gordeev wrote:
> > > Note that several callers pass NULL as addr, this is fine since
> > > virt_to_phys(0) == 0.
> 
> Missed that.
> 
> Are you sure? Quickly checked ppc64, x86 and arm64 - they do not 
> seem adhere virt_to_phys(0) == 0, nor the VR kernel (so far).

I think we do, but you are right - it might change in the future, so it's better to be on the safe side. Fixed in v2, thanks.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1] s390: ipl: fix physical-virtual confusion for diag308
  2023-03-10 12:42   ` Alexander Gordeev
  2023-03-10 13:05     ` Nico Boehr
@ 2023-03-10 13:20     ` Christian Borntraeger
  2023-03-10 13:31       ` Alexander Gordeev
  1 sibling, 1 reply; 7+ messages in thread
From: Christian Borntraeger @ 2023-03-10 13:20 UTC (permalink / raw)
  To: Alexander Gordeev, Nico Boehr; +Cc: hca, gor, svens, linux-s390, mhartmay



Am 10.03.23 um 13:42 schrieb Alexander Gordeev:
> On Fri, Mar 10, 2023 at 01:34:27PM +0100, Alexander Gordeev wrote:
>>> Note that several callers pass NULL as addr, this is fine since
>>> virt_to_phys(0) == 0.
> 
> Missed that.
> 
> Are you sure? Quickly checked ppc64, x86 and arm64 - they do not
> seem adhere virt_to_phys(0) == 0, nor the VR kernel (so far).

Isnt that the prefix page? I think we did say that the prefix page must be 0 in virt and phys otherwise we will have performance issues due to cache synonyms.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1] s390: ipl: fix physical-virtual confusion for diag308
  2023-03-10 13:20     ` Christian Borntraeger
@ 2023-03-10 13:31       ` Alexander Gordeev
  2023-03-10 13:37         ` Christian Borntraeger
  0 siblings, 1 reply; 7+ messages in thread
From: Alexander Gordeev @ 2023-03-10 13:31 UTC (permalink / raw)
  To: Christian Borntraeger; +Cc: Nico Boehr, hca, gor, svens, linux-s390, mhartmay

On Fri, Mar 10, 2023 at 02:20:32PM +0100, Christian Borntraeger wrote:
> > Are you sure? Quickly checked ppc64, x86 and arm64 - they do not
> > seem adhere virt_to_phys(0) == 0, nor the VR kernel (so far).
> 
> Isnt that the prefix page? I think we did say that the prefix page must be 0 in virt and phys otherwise we will have performance issues due to cache synonyms.

As far as I am concerned we should keep virt_to_phys() semantics in
sync with other archs and one should not rely on s390 implementation-
specifics. Please, see also my other reply to Nico in v2.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1] s390: ipl: fix physical-virtual confusion for diag308
  2023-03-10 13:31       ` Alexander Gordeev
@ 2023-03-10 13:37         ` Christian Borntraeger
  0 siblings, 0 replies; 7+ messages in thread
From: Christian Borntraeger @ 2023-03-10 13:37 UTC (permalink / raw)
  To: Alexander Gordeev; +Cc: Nico Boehr, hca, gor, svens, linux-s390, mhartmay



Am 10.03.23 um 14:31 schrieb Alexander Gordeev:
> On Fri, Mar 10, 2023 at 02:20:32PM +0100, Christian Borntraeger wrote:
>>> Are you sure? Quickly checked ppc64, x86 and arm64 - they do not
>>> seem adhere virt_to_phys(0) == 0, nor the VR kernel (so far).
>>
>> Isnt that the prefix page? I think we did say that the prefix page must be 0 in virt and phys otherwise we will have performance issues due to cache synonyms.
> 
> As far as I am concerned we should keep virt_to_phys() semantics in
> sync with other archs and one should not rely on s390 implementation-
> specifics. Please, see also my other reply to Nico in v2.

I agree with that.
I am just saying that we should never have virtual/real for prefix != 0 on current machines.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-03-10 13:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-10 12:22 [PATCH v1] s390: ipl: fix physical-virtual confusion for diag308 Nico Boehr
2023-03-10 12:34 ` Alexander Gordeev
2023-03-10 12:42   ` Alexander Gordeev
2023-03-10 13:05     ` Nico Boehr
2023-03-10 13:20     ` Christian Borntraeger
2023-03-10 13:31       ` Alexander Gordeev
2023-03-10 13:37         ` Christian Borntraeger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox