Skip to contentSkip to conversation

xen/arm: Add support for SMMUv3 driver

PATCH Superseded Rahul Singh 4 participants 34 messages Dec 10, 2020 – Dec 15, 2020 Page 2 of 2

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
Reviewed-by on v3 8/8
#29 lore raw

Re: [PATCH v3 8/8] xen/arm: smmuv3: Remove linux compatibility functions.

In reply to Rahul Singh

Hi Rahul,

Quoted 8 lines · Rahul Singh

Replace all Linux compatible device tree handling function with the XEN functions.

Replace all Linux ktime function with the XEN time functions.

Cheers
Bertrand

Quoted 94 lines

---
Changes in v3:
- This patch is introduce in this version.

---
xen/drivers/passthrough/arm/smmu-v3.c | 32 +++++++--------------------

1 file changed, 8 insertions(+), 24 deletions(-)
xen/drivers/passthrough/arm/smmu-v3.c +8 -24
index 65b3db94ad..c19c56ebc8 100644
@@ -101,22 +101,6 @@ typedef unsigned int		gfp_t;
 
 #define GFP_KERNEL		0
 
-/* Alias to Xen device tree helpers */
-#define device_node			dt_device_node
-#define of_phandle_args		dt_phandle_args
-#define of_device_id		dt_device_match
-#define of_match_node		dt_match_node
-#define of_property_read_u32(np, pname, out)	\
-		(!dt_property_read_u32(np, pname, out))
-#define of_property_read_bool		dt_property_read_bool
-#define of_parse_phandle_with_args	dt_parse_phandle_with_args
-
-/* Alias to Xen time functions */
-#define ktime_t s_time_t
-#define ktime_get()			(NOW())
-#define ktime_add_us(t, i)		(t + MICROSECS(i))
-#define ktime_compare(t, i)		(t > (i))
-
 /* Alias to Xen allocation helpers */
 #define kzalloc(size, flags)	_xzalloc(size, sizeof(void *))
 #define kfree	xfree
@@ -922,7 +906,7 @@ static void parse_driver_options(struct arm_smmu_device *smmu)
 	int i = 0;
 
 	do {
-		if (of_property_read_bool(smmu->dev->of_node,
+		if (dt_property_read_bool(smmu->dev->of_node,
 						arm_smmu_options[i].prop)) {
 			smmu->options |= arm_smmu_options[i].opt;
 			dev_notice(smmu->dev, "option %s\n",
@@ -994,17 +978,17 @@ static void queue_inc_prod(struct arm_smmu_ll_queue *q)
 */
 static int queue_poll_cons(struct arm_smmu_queue *q, bool sync, bool wfe)
 {
-	ktime_t timeout;
+	s_time_t timeout;
 	unsigned int delay = 1, spin_cnt = 0;
 
 	/* Wait longer if it's a CMD_SYNC */
-	timeout = ktime_add_us(ktime_get(), sync ?
+	timeout = NOW() + MICROSECS(sync ?
 					    ARM_SMMU_CMDQ_SYNC_TIMEOUT_US :
 					    ARM_SMMU_POLL_TIMEOUT_US);
 
 	while (queue_sync_cons_in(q),
 	      (sync ? !queue_empty(&q->llq) : queue_full(&q->llq))) {
-		if (ktime_compare(ktime_get(), timeout) > 0)
+		if ((NOW() > timeout) > 0)
 			return -ETIMEDOUT;
 
 		if (wfe) {
@@ -1232,13 +1216,13 @@ static void arm_smmu_cmdq_issue_cmd(struct arm_smmu_device *smmu,
 */
 static int __arm_smmu_sync_poll_msi(struct arm_smmu_device *smmu, u32 sync_idx)
 {
-	ktime_t timeout;
+	s_time_t timeout;
 	u32 val;
 
-	timeout = ktime_add_us(ktime_get(), ARM_SMMU_CMDQ_SYNC_TIMEOUT_US);
+	timeout = NOW() + MICROSECS(ARM_SMMU_CMDQ_SYNC_TIMEOUT_US);
 	val = smp_cond_load_acquire(&smmu->sync_count,
 				    (int)(VAL - sync_idx) >= 0 ||
-				    !ktime_before(ktime_get(), timeout));
+				    !(NOW() < timeout));
 
 	return (int)(val - sync_idx) < 0 ? -ETIMEDOUT : 0;
 }
@@ -2969,7 +2953,7 @@ static int arm_smmu_device_dt_probe(struct platform_device *pdev,
 	u32 cells;
 	int ret = -EINVAL;
 
-	if (of_property_read_u32(dev->of_node, "#iommu-cells", &cells))
+	if (!dt_property_read_u32(dev->of_node, "#iommu-cells", &cells))
 		dev_err(dev, "missing #iommu-cells property\n");
 	else if (cells != 1)
 		dev_err(dev, "invalid #iommu-cells value (%d)\n", cells);
Signature · 1 line
2.17.1
#30 lore raw

Re: [PATCH v3 8/8] xen/arm: smmuv3: Remove linux compatibility functions.

In reply to Rahul Singh

Hi Rahul,

Quoted 2 lines · Rahul Singh

Replace all Linux compatible device tree handling function with the XEN functions.

Right, but they were introduced in the previous patch. I dislike the idea to add code for removing afterwards (in some cases you actually do the renaming directly...).

So I would rather move this patch before patch #7 so we don't undo what we just did.

Cheers,

Signature · 1 line
Julien Grall
#31 lore raw
In reply to Rahul Singh

Hi Rahul,

Quoted 13 lines · Rahul Singh

This patch series is v3 of the work to add support for the SMMUv3 driver.

Approach taken is to first merge the Linux copy of the SMMUv3 driver (tag v5.8.18) and then modify the driver to build on XEN.

MSI and PCI ATS functionality are not supported. Code is not tested and compiled. Code is guarded by the flag CONFIG_PCI_ATS and CONFIG_MSI to compile the driver.

Code specific to Linux is removed from the driver to avoid dead code.

Driver is currently supported as tech preview.

Quoted 9 lines

Following functionality should be supported before driver is out for tech preview
1. Investigate the timing analysis of using spin lock in place of mutex when attaching a device to SMMU.
2. Merged the latest Linux SMMUv3 driver code once atomic operation is available in XEN.
3. PCI ATS and MSI interrupts should be supported.
4. Investigate side-effect of using tasklet in place of threaded IRQ and fix if any.

In your last e-mail, you wrote that you would investigate and then come back to use. It wasn't clear that this meant you will not deal with it in this series.

Quoted 1 line

5. fallthorugh keyword should be supported.

This one should really be done now... It is not a complicated one...

Quoted 1 line

6. Implement the ffsll function in bitops.h file.

... same here.

Cheers,

Signature · 1 line
Julien Grall
#32 lore raw

Hello Julien,Stefano

Quoted 22 lines · Julien Grall

Hi Rahul,

Quoted 9 lines · Rahul Singh

This patch series is v3 of the work to add support for the SMMUv3 driver. Approach taken is to first merge the Linux copy of the SMMUv3 driver (tag v5.8.18) and then modify the driver to build on XEN.
MSI and PCI ATS functionality are not supported. Code is not tested and compiled. Code is guarded by the flag CONFIG_PCI_ATS and CONFIG_MSI to compile the driver.
Code specific to Linux is removed from the driver to avoid dead code. Driver is currently supported as tech preview.
Following functionality should be supported before driver is out for tech

Quoted 8 lines

preview
1. Investigate the timing analysis of using spin lock in place of mutex when attaching a device to SMMU.
2. Merged the latest Linux SMMUv3 driver code once atomic operation is available in XEN.
3. PCI ATS and MSI interrupts should be supported.
4. Investigate side-effect of using tasklet in place of threaded IRQ and fix if any.

Quoted 2 lines

In your last e-mail, you wrote that you would investigate and then come back to use. It wasn't clear that this meant you will not deal with it in this series.

Yes, I will investigate the side-effect of using tasklet but not part of this patch series. It will be great if we proceed on this patch series as it is (using tasklet in place of threaded-IRQ).

Quoted 3 lines
Quoted 1 line

5. fallthorugh keyword should be supported.

This one should really be done now... It is not a complicated one...

Ok. I will implement in next version.

Quoted 2 lines
Quoted 2 lines

6. Implement the ffsll function in bitops.h file.

While implementing the code I found out that Linux is using the built-in function “__builtin_ffsll() “ for ffsll and there is no implementation available in Linux for ffsll. If we implement the ffsll in XEN we will diverge from Linux. I am thinking of adding the below code in "xen/include/asm-arm/bitops.h”.
Please suggest if it is okay?

static always_inline int ffsll(long long x)

{                                                                               
    return __builtin_ffsll(x);                                                    
}

Regards,
Rahul

Quoted 7 lines

... same here.

Cheers,

Signature · 1 line
Julien Grall
#33 lore raw
Quoted 38 lines · Rahul Singh

Hello Julien,Stefano

Quoted 22 lines · Julien Grall

Hi Rahul,

Quoted 9 lines · Rahul Singh

This patch series is v3 of the work to add support for the SMMUv3 driver. Approach taken is to first merge the Linux copy of the SMMUv3 driver (tag v5.8.18) and then modify the driver to build on XEN.
MSI and PCI ATS functionality are not supported. Code is not tested and compiled. Code is guarded by the flag CONFIG_PCI_ATS and CONFIG_MSI to compile the driver.
Code specific to Linux is removed from the driver to avoid dead code. Driver is currently supported as tech preview.
Following functionality should be supported before driver is out for tech

Quoted 8 lines

preview
1. Investigate the timing analysis of using spin lock in place of mutex when attaching a device to SMMU.
2. Merged the latest Linux SMMUv3 driver code once atomic operation is available in XEN.
3. PCI ATS and MSI interrupts should be supported.
4. Investigate side-effect of using tasklet in place of threaded IRQ and fix if any.

Quoted 2 lines

In your last e-mail, you wrote that you would investigate and then come back to use. It wasn't clear that this meant you will not deal with it in this series.

Yes, I will investigate the side-effect of using tasklet but not part of this patch series. It will be great if we proceed on this patch series as it is (using tasklet in place of threaded-IRQ).

Quoted 3 lines
Quoted 1 line

5. fallthorugh keyword should be supported.

This one should really be done now... It is not a complicated one...

Ok. I will implement in next version.

Quoted 2 lines
Quoted 2 lines

6. Implement the ffsll function in bitops.h file.

Quoted 8 lines

While implementing the code I found out that Linux is using the built-in function “__builtin_ffsll() “ for ffsll and there is no implementation available in Linux for ffsll. If we implement the ffsll in XEN we will diverge from Linux. I am thinking of adding the below code in "xen/include/asm-arm/bitops.h”.
Please suggest if it is okay?

static always_inline int ffsll(long long x)

{                                                                               
    return __builtin_ffsll(x);                                                    
}

I think that's OK if it builds with clang too.