Re: static analysis bug report in drivers/staging/iio/dac/ad5380.c

2019-08-15 Thread Lars-Peter Clausen
On 8/15/19 12:21 PM, Colin Ian King wrote:
> Hi,
> 
> Static analysis with Coverity Scan has detected a potential assignment
> bug in ad5380.c:
> 
> 217case IIO_CHAN_INFO_CALIBBIAS:
> 218ret = regmap_read(st->regmap,
> AD5380_REG_OFFSET(chan->address),
> 219val);
> 220if (ret)
> 221return ret;
> 222*val >>= chan->scan_type.shift;
> 
> CID 43178 (#1 of 1): Unused value (UNUSED_VALUE)assigned_pointer:
> Assigning value from val - (1 << chan->scan_type.realbits) / 2 to val
> here, but that stored value is not used.
> 
> 223val -= (1 << chan->scan_type.realbits) / 2;
> 224return IIO_VAL_INT;
> 
> val is a pointer and so updating it before a return is probably not the
> intention.  I suspect the intention was probably:
> 
>  *val -= (1 << chan->scan_type.realbits) / 2;
> 
> However, I'm not confident about this as the following case has:
> 
> 225case IIO_CHAN_INFO_SCALE:
> 226*val = 2 * st->vref;
> 227*val2 = chan->scan_type.realbits;
> 228return IIO_VAL_FRACTIONAL_LOG2;
> 
> which may imply the update maybe to *val2 instead, e.g.:
> 
>   *val2 -= (1 << chan->scan_type.realbits) / 2;
> 
> Any ideas?

Updating changing val to *val is the right fix in this case.
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging: comedi: usbduxsigma: remove redundant assignment to variable fx2delay

2019-08-15 Thread Ian Abbott

On 15/08/2019 11:53, Colin King wrote:

From: Colin Ian King 

Variable fx2delay is being initialized with a value that is never read
and fx2delay is being re-assigned a little later on. The assignment is
redundant and hence can be removed.

Addresses-Coverity: ("Unused value")
Signed-off-by: Colin Ian King 
---
  drivers/staging/comedi/drivers/usbduxsigma.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/comedi/drivers/usbduxsigma.c 
b/drivers/staging/comedi/drivers/usbduxsigma.c
index 3cc40d2544be..54d7605e909f 100644
--- a/drivers/staging/comedi/drivers/usbduxsigma.c
+++ b/drivers/staging/comedi/drivers/usbduxsigma.c
@@ -1074,7 +1074,7 @@ static int usbduxsigma_pwm_period(struct comedi_device 
*dev,
  unsigned int period)
  {
struct usbduxsigma_private *devpriv = dev->private;
-   int fx2delay = 255;
+   int fx2delay;
  
  	if (period < MIN_PWM_PERIOD)

return -EAGAIN;



Looks fine, thanks!

Reviewed-by: Ian Abbott 

--
-=( Ian Abbott  || Web: www.mev.co.uk )=-
-=( MEV Ltd. is a company registered in England & Wales. )=-
-=( Registered number: 02862268.  Registered address:)=-
-=( 15 West Park Road, Bramhall, STOCKPORT, SK7 3JZ, UK. )=-
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: sm750fb: fix odd license text

2019-08-15 Thread Greg Kroah-Hartman
There is some "confusing" license text in some of the sm750fb driver
files.  After discussing it with the company, it turns out to have been
a mistake and these lines can be safely removed.  The files are all to
be licensed under the GPLv2 license.

Cc: Sudip Mukherjee 
Cc: Teddy Wang 
Cc: linux-fb...@vger.kernel.org
Cc: de...@driverdev.osuosl.org
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/staging/sm750fb/ddk750.h   | 3 ---
 drivers/staging/sm750fb/ddk750_swi2c.c | 3 ---
 drivers/staging/sm750fb/ddk750_swi2c.h | 3 ---
 3 files changed, 9 deletions(-)

diff --git a/drivers/staging/sm750fb/ddk750.h b/drivers/staging/sm750fb/ddk750.h
index 482c1c6ba422..64ef4d258a91 100644
--- a/drivers/staging/sm750fb/ddk750.h
+++ b/drivers/staging/sm750fb/ddk750.h
@@ -2,9 +2,6 @@
 /*
  * Copyright (c) 2007 by Silicon Motion, Inc. (SMI)
  *
- *  All rights are reserved. Reproduction or in part is prohibited
- *  without the written consent of the copyright owner.
- *
  *  RegSC.h --- SM718 SDK
  *  This file contains the definitions for the System Configuration registers.
  */
diff --git a/drivers/staging/sm750fb/ddk750_swi2c.c 
b/drivers/staging/sm750fb/ddk750_swi2c.c
index 5c0ac747ea2b..0ef8d4ff2ef9 100644
--- a/drivers/staging/sm750fb/ddk750_swi2c.c
+++ b/drivers/staging/sm750fb/ddk750_swi2c.c
@@ -2,9 +2,6 @@
 /*
  * Copyright (c) 2007 by Silicon Motion, Inc. (SMI)
  *
- *  All rights are reserved. Reproduction or in part is prohibited
- *  without the written consent of the copyright owner.
- *
  *  swi2c.c --- SM750/SM718 DDK
  *  This file contains the source code for I2C using software
  *  implementation.
diff --git a/drivers/staging/sm750fb/ddk750_swi2c.h 
b/drivers/staging/sm750fb/ddk750_swi2c.h
index 5868feea791b..dfa166060da7 100644
--- a/drivers/staging/sm750fb/ddk750_swi2c.h
+++ b/drivers/staging/sm750fb/ddk750_swi2c.h
@@ -2,9 +2,6 @@
 /*
  * Copyright (c) 2007 by Silicon Motion, Inc. (SMI)
  *
- *  All rights are reserved. Reproduction or in part is prohibited
- *  without the written consent of the copyright owner.
- *
  *  swi2c.h --- SM750/SM718 DDK
  *  This file contains the definitions for i2c using software
  *  implementation.
-- 
2.22.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v8 00/24] erofs: promote erofs from staging v8

2019-08-15 Thread Greg Kroah-Hartman
On Thu, Aug 15, 2019 at 12:41:31PM +0800, Gao Xiang wrote:
> [I strip the previous cover letter, the old one can be found in v6:
>  https://lore.kernel.org/r/20190802125347.166018-1-gaoxian...@huawei.com/]
> 
> We'd like to submit a formal moving patch applied to staging tree
> for 5.4, before that we'd like to hear if there are some ACKs,
> suggestions or NAKs, objections of EROFS. Therefore, we can improve
> it in this round or rethink about the whole thing.
> 
> As related materials mentioned [1] [2], the goal of EROFS is to
> save extra storage space with guaranteed end-to-end performance
> for read-only files, which has better performance over exist Linux
> compression filesystems based on fixed-sized output compression
> and inplace decompression. It even has better performance in
> a large compression ratio range compared with generic uncompressed
> filesystems with proper CPU-storage combinations. And we think this
> direction is correct and a dedicated kernel team is continuously /
> actively working on improving it, enough testers and beta / end
> users using it.
> 
> EROFS has been applied to almost all in-service HUAWEI smartphones
> (Yes, the number is still increasing by time) and it seems like
> a success. It can be used in more wider scenarios. We think it's
> useful for Linux / Android OS community and it's the time moving
> out of staging.
> 
> In order to get started, latest stable mkfs.erofs is available at
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git -b dev
> 
> with README in the repository.
> 
> We are still tuning sequential read performance for ultra-fast
> speed NVME SSDs like Samsung 970PRO, but at least now you can
> try on your PC with some data with proper compression ratio,
> the latest Linux kernel, USB stick for convenience sake and
> a not very old-fashioned CPU. There are also benchmarks available
> in the above materials mentioned.
> 
> EROFS is a self-contained filesystem driver. Although there are
> still some TODOs to be more generic, we will actively keep on
> developping / tuning EROFS with the evolution of Linux kernel
> as the other in-kernel filesystems.
> 
> As I mentioned before in LSF/MM 2019, in the future, we'd like
> to generalize the decompression engine into a library for other
> fses to use after the whole system is mature like fscrypt.
> However, such metadata should be designed respectively for
> each fs, and synchronous metadata read cost will be larger
> than EROFS because of those ondisk limitation. Therefore EROFS
> is still a better choice for read-only scenarios.
> 
> EROFS is now ready for reviewing and moving, and the code is
> already cleaned up as shiny floors... Please kindly take some
> precious time, share your comments about EROFS and let us know
> your opinion about this. It's really important for us since
> generally speaking, we like to use Linux _in-tree_ stuffs rather
> than lack of supported out-of-tree / orphan stuffs as well.

I know everyone is busy, but given the length this has been in staging,
and the constant good progress toward cleaning it all up that has been
happening, I want to get this moved out of staging soon.

So, unless there are any objections, I'll take this patchset in a week
into my staging tree to move the filesystem into the "real" part of the
kernel.

thanks,

greg k-h
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v7 08/24] erofs: add namei functions

2019-08-15 Thread Gao Xiang
Hi Pavel,

On Thu, Aug 15, 2019 at 09:01:32AM +0200, Pavel Machek wrote:
> Hi!
> 
> > > > +   /*
> > > > +* on-disk error, let's only BUG_ON in the debugging mode.
> > > > +* otherwise, it will return 1 to just skip the invalid name
> > > > +* and go on (in consideration of the lookup performance).
> > > > +*/
> > > > +   DBG_BUGON(qd->name > qd->end);
> > > 
> > > I believe you should check for errors in non-debug mode, too.
> > 
> > Thanks for your kindly reply!
> > 
> > The following is just my personal thought... If I am wrong, please
> > kindly point out...
> > 
> > As you can see, this is a new prefixed string binary search algorithm
> > which can provide similar performance with hashed approach (but no
> > need to store hash value at all), so I really care about its lookup
> > performance.
> > 
> > There is something needing to be concerned, is, whether namei() should
> > report any potential on-disk issues or just return -ENOENT for these
> > corrupted dirs, I think I tend to use the latter one.
> 
> -ENOENT is okay for corrupted directories, as long as corrupted
> directories do not cause some kind of security bugs (memory
> corruption, crashes, ...)

Yes, I am certain that it will return -ENOENT for such corrupted
directories and it will certainly not crash the kernel as well.

I have fuzzed it for several months and it seems fine after
commit 419d6efc50e9 ("staging: erofs: keep corrupted fs from crashing kernel in 
erofs_namei()")

Don't worry about that :)

Thanks,
Gao Xiang

> 
> 
> Best regards,
>   Pavel
> -- 
> DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany


___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v7 08/24] erofs: add namei functions

2019-08-15 Thread Pavel Machek
Hi!

> > > + /*
> > > +  * on-disk error, let's only BUG_ON in the debugging mode.
> > > +  * otherwise, it will return 1 to just skip the invalid name
> > > +  * and go on (in consideration of the lookup performance).
> > > +  */
> > > + DBG_BUGON(qd->name > qd->end);
> > 
> > I believe you should check for errors in non-debug mode, too.
> 
> Thanks for your kindly reply!
> 
> The following is just my personal thought... If I am wrong, please
> kindly point out...
> 
> As you can see, this is a new prefixed string binary search algorithm
> which can provide similar performance with hashed approach (but no
> need to store hash value at all), so I really care about its lookup
> performance.
> 
> There is something needing to be concerned, is, whether namei() should
> report any potential on-disk issues or just return -ENOENT for these
> corrupted dirs, I think I tend to use the latter one.

-ENOENT is okay for corrupted directories, as long as corrupted
directories do not cause some kind of security bugs (memory
corruption, crashes, ...)


Best regards,
Pavel
-- 
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany


signature.asc
Description: Digital signature
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


static analysis bug report in drivers/staging/iio/dac/ad5380.c

2019-08-15 Thread Colin Ian King
Hi,

Static analysis with Coverity Scan has detected a potential assignment
bug in ad5380.c:

217case IIO_CHAN_INFO_CALIBBIAS:
218ret = regmap_read(st->regmap,
AD5380_REG_OFFSET(chan->address),
219val);
220if (ret)
221return ret;
222*val >>= chan->scan_type.shift;

CID 43178 (#1 of 1): Unused value (UNUSED_VALUE)assigned_pointer:
Assigning value from val - (1 << chan->scan_type.realbits) / 2 to val
here, but that stored value is not used.

223val -= (1 << chan->scan_type.realbits) / 2;
224return IIO_VAL_INT;

val is a pointer and so updating it before a return is probably not the
intention.  I suspect the intention was probably:

   *val -= (1 << chan->scan_type.realbits) / 2;

However, I'm not confident about this as the following case has:

225case IIO_CHAN_INFO_SCALE:
226*val = 2 * st->vref;
227*val2 = chan->scan_type.realbits;
228return IIO_VAL_FRACTIONAL_LOG2;

which may imply the update maybe to *val2 instead, e.g.:

*val2 -= (1 << chan->scan_type.realbits) / 2;

Any ideas?

Colin
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: comedi: usbduxsigma: remove redundant assignment to variable fx2delay

2019-08-15 Thread Colin King
From: Colin Ian King 

Variable fx2delay is being initialized with a value that is never read
and fx2delay is being re-assigned a little later on. The assignment is
redundant and hence can be removed.

Addresses-Coverity: ("Unused value")
Signed-off-by: Colin Ian King 
---
 drivers/staging/comedi/drivers/usbduxsigma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/comedi/drivers/usbduxsigma.c 
b/drivers/staging/comedi/drivers/usbduxsigma.c
index 3cc40d2544be..54d7605e909f 100644
--- a/drivers/staging/comedi/drivers/usbduxsigma.c
+++ b/drivers/staging/comedi/drivers/usbduxsigma.c
@@ -1074,7 +1074,7 @@ static int usbduxsigma_pwm_period(struct comedi_device 
*dev,
  unsigned int period)
 {
struct usbduxsigma_private *devpriv = dev->private;
-   int fx2delay = 255;
+   int fx2delay;
 
if (period < MIN_PWM_PERIOD)
return -EAGAIN;
-- 
2.20.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: rtl8192u: fix up indentation of a statement

2019-08-15 Thread Colin King
From: Colin Ian King 

There is a statement that is indented one level too deeply, remove
the extraneous tab.

Addresses-Coverity: ("Identation does not match nesting level")
Signed-off-by: Colin Ian King 
---
 drivers/staging/rtl8192u/r8190_rtl8256.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8192u/r8190_rtl8256.c 
b/drivers/staging/rtl8192u/r8190_rtl8256.c
index 92de92a3325a..0bedf88525cd 100644
--- a/drivers/staging/rtl8192u/r8190_rtl8256.c
+++ b/drivers/staging/rtl8192u/r8190_rtl8256.c
@@ -289,8 +289,8 @@ void phy_set_rf8256_ofdm_tx_power(struct net_device *dev, 
u8 powerlevel)
writeVal = 0x03030303;
} else {
writeVal = (byte3<<24) | (byte2<<16) | (byte1<<8) | 
byte0;
-   }
-   rtl8192_setBBreg(dev, RegOffset[index], 0x7f7f7f7f, 
writeVal);
+   }
+   rtl8192_setBBreg(dev, RegOffset[index], 0x7f7f7f7f, writeVal);
}
return;
 
-- 
2.20.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v2] staging: drivers: rtl8712: removing unnecessary parenthesis

2019-08-15 Thread Greg KH
On Thu, Aug 15, 2019 at 11:26:40AM -0400, hugoziviani wrote:
> Fix checkpatch error "CHECK: Remove unecessary parenthesis in 
> drivers/staging/rtl8712/rtl871x_mlme.c"
> 
> Signed-off-by: hugoziviani 
> ---
>  drivers/staging/rtl8712/rtl871x_mlme.c | 84 +-
>  1 file changed, 42 insertions(+), 42 deletions(-)

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman.  You have sent him
a patch that has triggered this response.  He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created.  Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.

You are receiving this message because of the following common error(s)
as indicated below:

- It looks like you did not use your "real" name for the patch on either
  the Signed-off-by: line, or the From: line (both of which have to
  match).  Please read the kernel file, Documentation/SubmittingPatches
  for how to do this correctly.

If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.

thanks,

greg k-h's patch email bot
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v8 00/24] erofs: promote erofs from staging v8

2019-08-15 Thread Linus Torvalds
On Thu, Aug 15, 2019 at 2:06 AM Greg Kroah-Hartman
 wrote:
>
> I know everyone is busy, but given the length this has been in staging,
> and the constant good progress toward cleaning it all up that has been
> happening, I want to get this moved out of staging soon.

Since it doesn't touch anything outside of its own filesystem, I have
no real objections. We've never had huge problems with odd
filesystems.

I read through the patches to look for syntactic stuff (ie very much
*not* looking at actual code working or not), and had only one
comment. It's not critical, but it would be nice to do as part of (or
before) the "get it out of staging".

 Linus
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v3 1/2] binder: Add default binder devices through binderfs when configured

2019-08-15 Thread Joel Fernandes
On Thu, Aug 08, 2019 at 03:27:25PM -0700, Hridya Valsaraju wrote:
> Currently, since each binderfs instance needs its own
> private binder devices, every time a binderfs instance is
> mounted, all the default binder devices need to be created
> via the BINDER_CTL_ADD IOCTL. This patch aims to
> add a solution to automatically create the default binder
> devices for each binderfs instance that gets mounted.
> To achieve this goal, when CONFIG_ANDROID_BINDERFS is set,
> the default binder devices specified by CONFIG_ANDROID_BINDER_DEVICES
> are created in each binderfs instance instead of global devices
> being created by the binder driver.
> 
> Co-developed-by: Christian Brauner 
> Signed-off-by: Christian Brauner 
> Signed-off-by: Hridya Valsaraju 
> ---

Reviewed-by: Joel Fernandes (Google) 

thanks,

 - Joel

> 
> Changes in v2:
> - Updated commit message as per Greg Kroah-Hartman.
> - Removed new module parameter creation as per Greg
>   Kroah-Hartman/Christian Brauner.
> - Refactored device name length check into a new patch as per Greg 
> Kroah-Hartman.
> 
> Changes in v3:
> -Removed unnecessary empty lines as per Dan Carpenter.
> 
>  drivers/android/binder.c  |  5 +++--
>  drivers/android/binder_internal.h |  2 ++
>  drivers/android/binderfs.c| 23 ---
>  3 files changed, 25 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/android/binder.c b/drivers/android/binder.c
> index 466b6a7f8ab7..ca6b21a53321 100644
> --- a/drivers/android/binder.c
> +++ b/drivers/android/binder.c
> @@ -123,7 +123,7 @@ static uint32_t binder_debug_mask = 
> BINDER_DEBUG_USER_ERROR |
>   BINDER_DEBUG_FAILED_TRANSACTION | BINDER_DEBUG_DEAD_TRANSACTION;
>  module_param_named(debug_mask, binder_debug_mask, uint, 0644);
>  
> -static char *binder_devices_param = CONFIG_ANDROID_BINDER_DEVICES;
> +char *binder_devices_param = CONFIG_ANDROID_BINDER_DEVICES;
>  module_param_named(devices, binder_devices_param, charp, 0444);
>  
>  static DECLARE_WAIT_QUEUE_HEAD(binder_user_error_wait);
> @@ -6279,7 +6279,8 @@ static int __init binder_init(void)
>   _log_fops);
>   }
>  
> - if (strcmp(binder_devices_param, "") != 0) {
> + if (!IS_ENABLED(CONFIG_ANDROID_BINDERFS) &&
> + strcmp(binder_devices_param, "") != 0) {
>   /*
>   * Copy the module_parameter string, because we don't want to
>   * tokenize it in-place.
> diff --git a/drivers/android/binder_internal.h 
> b/drivers/android/binder_internal.h
> index 045b3e42d98b..fe8c745dc8e0 100644
> --- a/drivers/android/binder_internal.h
> +++ b/drivers/android/binder_internal.h
> @@ -37,6 +37,8 @@ struct binder_device {
>  
>  extern const struct file_operations binder_fops;
>  
> +extern char *binder_devices_param;
> +
>  #ifdef CONFIG_ANDROID_BINDERFS
>  extern bool is_binderfs_device(const struct inode *inode);
>  #else
> diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c
> index e773f45d19d9..aee46dd1be91 100644
> --- a/drivers/android/binderfs.c
> +++ b/drivers/android/binderfs.c
> @@ -186,8 +186,7 @@ static int binderfs_binder_device_create(struct inode 
> *ref_inode,
>   req->major = MAJOR(binderfs_dev);
>   req->minor = minor;
>  
> - ret = copy_to_user(userp, req, sizeof(*req));
> - if (ret) {
> + if (userp && copy_to_user(userp, req, sizeof(*req))) {
>   ret = -EFAULT;
>   goto err;
>   }
> @@ -467,6 +466,9 @@ static int binderfs_fill_super(struct super_block *sb, 
> void *data, int silent)
>   int ret;
>   struct binderfs_info *info;
>   struct inode *inode = NULL;
> + struct binderfs_device device_info = { 0 };
> + const char *name;
> + size_t len;
>  
>   sb->s_blocksize = PAGE_SIZE;
>   sb->s_blocksize_bits = PAGE_SHIFT;
> @@ -521,7 +523,22 @@ static int binderfs_fill_super(struct super_block *sb, 
> void *data, int silent)
>   if (!sb->s_root)
>   return -ENOMEM;
>  
> - return binderfs_binder_ctl_create(sb);
> + ret = binderfs_binder_ctl_create(sb);
> + if (ret)
> + return ret;
> +
> + name = binder_devices_param;
> + for (len = strcspn(name, ","); len > 0; len = strcspn(name, ",")) {
> + strscpy(device_info.name, name, len + 1);
> + ret = binderfs_binder_device_create(inode, NULL, _info);
> + if (ret)
> + return ret;
> + name += len;
> + if (*name == ',')
> + name++;
> + }
> +
> + return 0;
>  }
>  
>  static struct dentry *binderfs_mount(struct file_system_type *fs_type,
> -- 
> 2.22.0.770.g0f2c4a37fd-goog
> 
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v8 00/24] erofs: promote erofs from staging v8

2019-08-15 Thread Gao Xiang
Hi Linus,

On Thu, Aug 15, 2019 at 09:18:12AM -0700, Linus Torvalds wrote:
> On Thu, Aug 15, 2019 at 2:06 AM Greg Kroah-Hartman
>  wrote:
> >
> > I know everyone is busy, but given the length this has been in staging,
> > and the constant good progress toward cleaning it all up that has been
> > happening, I want to get this moved out of staging soon.
> 
> Since it doesn't touch anything outside of its own filesystem, I have
> no real objections. We've never had huge problems with odd
> filesystems.
> 
> I read through the patches to look for syntactic stuff (ie very much
> *not* looking at actual code working or not), and had only one
> comment. It's not critical, but it would be nice to do as part of (or
> before) the "get it out of staging".

Thanks for your kind reply!

OK, I will submit a patch later to address your comment and
a pending formal moving patch with a suggestion by Stephen earlier
for Greg as well.

Thanks,
Gao Xiang

> 
>  Linus
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2] staging: drivers: rtl8712: removing unnecessary parenthesis

2019-08-15 Thread hugoziviani
Fix checkpatch error "CHECK: Remove unecessary parenthesis in 
drivers/staging/rtl8712/rtl871x_mlme.c"

Signed-off-by: hugoziviani 
---
 drivers/staging/rtl8712/rtl871x_mlme.c | 84 +-
 1 file changed, 42 insertions(+), 42 deletions(-)

diff --git a/drivers/staging/rtl8712/rtl871x_mlme.c 
b/drivers/staging/rtl8712/rtl871x_mlme.c
index 3f17ef6f7..439eddcbf 100644
--- a/drivers/staging/rtl8712/rtl871x_mlme.c
+++ b/drivers/staging/rtl8712/rtl871x_mlme.c
@@ -44,10 +44,10 @@ static sint _init_mlme_priv(struct _adapter *padapter)
 Ndis802_11AutoUnknown;
/* Maybe someday we should rename this variable to "active_mode"(Jeff)*/
pmlmepriv->passive_mode = 1; /* 1: active, 0: passive. */
-   spin_lock_init(&(pmlmepriv->lock));
-   spin_lock_init(&(pmlmepriv->lock2));
-   _init_queue(&(pmlmepriv->free_bss_pool));
-   _init_queue(&(pmlmepriv->scanned_queue));
+   spin_lock_init(>lock);
+   spin_lock_init(>lock2);
+   _init_queue(>free_bss_pool);
+   _init_queue(>scanned_queue);
set_scanned_network_val(pmlmepriv, 0);
memset(>assoc_ssid, 0, sizeof(struct ndis_802_11_ssid));
pbuf = kmalloc_array(MAX_BSS_CNT, sizeof(struct wlan_network),
@@ -57,9 +57,9 @@ static sint _init_mlme_priv(struct _adapter *padapter)
pmlmepriv->free_bss_buf = pbuf;
pnetwork = (struct wlan_network *)pbuf;
for (i = 0; i < MAX_BSS_CNT; i++) {
-   INIT_LIST_HEAD(&(pnetwork->list));
-   list_add_tail(&(pnetwork->list),
-&(pmlmepriv->free_bss_pool.queue));
+   INIT_LIST_HEAD(>list);
+   list_add_tail(>list,
+ >free_bss_pool.queue);
pnetwork++;
}
pmlmepriv->sitesurveyctrl.last_rx_pkts = 0;
@@ -93,7 +93,7 @@ static void _free_network(struct mlme_priv *pmlmepriv,
 {
u32 curr_time, delta_time;
unsigned long irqL;
-   struct  __queue *free_queue = &(pmlmepriv->free_bss_pool);
+   struct  __queue *free_queue = >free_bss_pool;
 
if (pnetwork == NULL)
return;
@@ -244,8 +244,8 @@ int r8712_is_same_ibss(struct _adapter *adapter, struct 
wlan_network *pnetwork)
int ret = true;
struct security_priv *psecuritypriv = >securitypriv;
 
-   if ((psecuritypriv->PrivacyAlgrthm != _NO_PRIVACY_) &&
-   (pnetwork->network.Privacy == cpu_to_le32(0)))
+   if (psecuritypriv->PrivacyAlgrthm != _NO_PRIVACY_ &&
+   pnetwork->network.Privacy == cpu_to_le32(0))
ret = false;
else if ((psecuritypriv->PrivacyAlgrthm == _NO_PRIVACY_) &&
 (pnetwork->network.Privacy == cpu_to_le32(1)))
@@ -310,7 +310,7 @@ static void update_network(struct wlan_bssid_ex *dst,
struct smooth_rssi_data *sqd = >recvpriv.signal_qual_data;
 
if (check_fwstate(>mlmepriv, _FW_LINKED) &&
-   is_same_network(&(padapter->mlmepriv.cur_network.network), src)) {
+   is_same_network(>mlmepriv.cur_network.network, src)) {
if (padapter->recvpriv.signal_qual_data.total_num++ >=
PHY_LINKQUALITY_SLID_WIN_MAX) {
padapter->recvpriv.signal_qual_data.total_num =
@@ -342,8 +342,8 @@ static void update_current_network(struct _adapter *adapter,
 {
struct mlme_priv *pmlmepriv = >mlmepriv;
 
-   if (is_same_network(&(pmlmepriv->cur_network.network), pnetwork)) {
-   update_network(&(pmlmepriv->cur_network.network),
+   if (is_same_network(>cur_network.network, pnetwork)) {
+   update_network(>cur_network.network,
   pnetwork, adapter);
r8712_update_protection(adapter,
   (pmlmepriv->cur_network.network.IEs) +
@@ -452,8 +452,8 @@ static int is_desired_network(struct _adapter *adapter,
return true;
return false;
}
-   if ((psecuritypriv->PrivacyAlgrthm != _NO_PRIVACY_) &&
-   (pnetwork->network.Privacy == 0))
+   if (psecuritypriv->PrivacyAlgrthm != _NO_PRIVACY_ &&
+   pnetwork->network.Privacy == 0)
bselected = false;
if (check_fwstate(>mlmepriv, WIFI_ADHOC_STATE)) {
if (pnetwork->network.InfrastructureMode !=
@@ -510,7 +510,7 @@ void r8712_survey_event_callback(struct _adapter *adapter, 
u8 *pbuf)
spin_lock_irqsave(>lock2, flags);
/* update IBSS_network 's timestamp */
if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
-   if (!memcmp(&(pmlmepriv->cur_network.network.MacAddress),
+   if (!memcmp(>cur_network.network.MacAddress,
pnetwork->MacAddress, ETH_ALEN)) {
struct wlan_network *ibss_wlan = NULL;
 
@@ -564,7 +564,7 @@ void r8712_surveydone_event_callback(struct _adapter 
*adapter, u8 *pbuf)

Re: [PATCH v3 1/2] binder: Add default binder devices through binderfs when configured

2019-08-15 Thread Joel Fernandes
On Thu, Aug 08, 2019 at 03:27:25PM -0700, Hridya Valsaraju wrote:
> Currently, since each binderfs instance needs its own
> private binder devices, every time a binderfs instance is
> mounted, all the default binder devices need to be created
> via the BINDER_CTL_ADD IOCTL. This patch aims to
> add a solution to automatically create the default binder
> devices for each binderfs instance that gets mounted.
> To achieve this goal, when CONFIG_ANDROID_BINDERFS is set,
> the default binder devices specified by CONFIG_ANDROID_BINDER_DEVICES
> are created in each binderfs instance instead of global devices
> being created by the binder driver.
> 
> Co-developed-by: Christian Brauner 
> Signed-off-by: Christian Brauner 
> Signed-off-by: Hridya Valsaraju 

Reviewed-by: Joel Fernandes (Google) 

thanks,

 - Joel

> ---
> 
> Changes in v2:
> - Updated commit message as per Greg Kroah-Hartman.
> - Removed new module parameter creation as per Greg
>   Kroah-Hartman/Christian Brauner.
> - Refactored device name length check into a new patch as per Greg 
> Kroah-Hartman.
> 
> Changes in v3:
> -Removed unnecessary empty lines as per Dan Carpenter.
> 
>  drivers/android/binder.c  |  5 +++--
>  drivers/android/binder_internal.h |  2 ++
>  drivers/android/binderfs.c| 23 ---
>  3 files changed, 25 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/android/binder.c b/drivers/android/binder.c
> index 466b6a7f8ab7..ca6b21a53321 100644
> --- a/drivers/android/binder.c
> +++ b/drivers/android/binder.c
> @@ -123,7 +123,7 @@ static uint32_t binder_debug_mask = 
> BINDER_DEBUG_USER_ERROR |
>   BINDER_DEBUG_FAILED_TRANSACTION | BINDER_DEBUG_DEAD_TRANSACTION;
>  module_param_named(debug_mask, binder_debug_mask, uint, 0644);
>  
> -static char *binder_devices_param = CONFIG_ANDROID_BINDER_DEVICES;
> +char *binder_devices_param = CONFIG_ANDROID_BINDER_DEVICES;
>  module_param_named(devices, binder_devices_param, charp, 0444);
>  
>  static DECLARE_WAIT_QUEUE_HEAD(binder_user_error_wait);
> @@ -6279,7 +6279,8 @@ static int __init binder_init(void)
>   _log_fops);
>   }
>  
> - if (strcmp(binder_devices_param, "") != 0) {
> + if (!IS_ENABLED(CONFIG_ANDROID_BINDERFS) &&
> + strcmp(binder_devices_param, "") != 0) {
>   /*
>   * Copy the module_parameter string, because we don't want to
>   * tokenize it in-place.
> diff --git a/drivers/android/binder_internal.h 
> b/drivers/android/binder_internal.h
> index 045b3e42d98b..fe8c745dc8e0 100644
> --- a/drivers/android/binder_internal.h
> +++ b/drivers/android/binder_internal.h
> @@ -37,6 +37,8 @@ struct binder_device {
>  
>  extern const struct file_operations binder_fops;
>  
> +extern char *binder_devices_param;
> +
>  #ifdef CONFIG_ANDROID_BINDERFS
>  extern bool is_binderfs_device(const struct inode *inode);
>  #else
> diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c
> index e773f45d19d9..aee46dd1be91 100644
> --- a/drivers/android/binderfs.c
> +++ b/drivers/android/binderfs.c
> @@ -186,8 +186,7 @@ static int binderfs_binder_device_create(struct inode 
> *ref_inode,
>   req->major = MAJOR(binderfs_dev);
>   req->minor = minor;
>  
> - ret = copy_to_user(userp, req, sizeof(*req));
> - if (ret) {
> + if (userp && copy_to_user(userp, req, sizeof(*req))) {
>   ret = -EFAULT;
>   goto err;
>   }
> @@ -467,6 +466,9 @@ static int binderfs_fill_super(struct super_block *sb, 
> void *data, int silent)
>   int ret;
>   struct binderfs_info *info;
>   struct inode *inode = NULL;
> + struct binderfs_device device_info = { 0 };
> + const char *name;
> + size_t len;
>  
>   sb->s_blocksize = PAGE_SIZE;
>   sb->s_blocksize_bits = PAGE_SHIFT;
> @@ -521,7 +523,22 @@ static int binderfs_fill_super(struct super_block *sb, 
> void *data, int silent)
>   if (!sb->s_root)
>   return -ENOMEM;
>  
> - return binderfs_binder_ctl_create(sb);
> + ret = binderfs_binder_ctl_create(sb);
> + if (ret)
> + return ret;
> +
> + name = binder_devices_param;
> + for (len = strcspn(name, ","); len > 0; len = strcspn(name, ",")) {
> + strscpy(device_info.name, name, len + 1);
> + ret = binderfs_binder_device_create(inode, NULL, _info);
> + if (ret)
> + return ret;
> + name += len;
> + if (*name == ',')
> + name++;
> + }
> +
> + return 0;
>  }
>  
>  static struct dentry *binderfs_mount(struct file_system_type *fs_type,
> -- 
> 2.22.0.770.g0f2c4a37fd-goog
> 
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v3 0/2] Add default binderfs devices

2019-08-15 Thread Greg Kroah-Hartman
On Thu, Aug 08, 2019 at 03:27:24PM -0700, Hridya Valsaraju wrote:
> Binderfs was created to help provide private binder devices to
> containers in their own IPC namespace. Currently, every time a new binderfs
> instance is mounted, its private binder devices need to be created via
> IOCTL calls. This patch series eliminates the effort for creating
> the default binder devices for each binderfs instance by creating them
> automatically.
> 
> Hridya Valsaraju (2):
>   binder: Add default binder devices through binderfs when configured
>   binder: Validate the default binderfs device names.

I'd like to get a reviewed-by from the other binder maintainers before
taking this series

{hint}

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v3 2/2] binder: Validate the default binderfs device names.

2019-08-15 Thread Joel Fernandes
On Thu, Aug 08, 2019 at 03:27:26PM -0700, Hridya Valsaraju wrote:
> Length of a binderfs device name cannot exceed BINDERFS_MAX_NAME.
> This patch adds a check in binderfs_init() to ensure the same
> for the default binder devices that will be created in every
> binderfs instance.
> 
> Co-developed-by: Christian Brauner 
> Signed-off-by: Christian Brauner 
> Signed-off-by: Hridya Valsaraju 
> ---

Reviewed-by: Joel Fernandes (Google) 

thanks,

 - Joel

>  drivers/android/binderfs.c | 12 
>  1 file changed, 12 insertions(+)
> 
> diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c
> index aee46dd1be91..55c5adb87585 100644
> --- a/drivers/android/binderfs.c
> +++ b/drivers/android/binderfs.c
> @@ -570,6 +570,18 @@ static struct file_system_type binder_fs_type = {
>  int __init init_binderfs(void)
>  {
>   int ret;
> + const char *name;
> + size_t len;
> +
> + /* Verify that the default binderfs device names are valid. */
> + name = binder_devices_param;
> + for (len = strcspn(name, ","); len > 0; len = strcspn(name, ",")) {
> + if (len > BINDERFS_MAX_NAME)
> + return -E2BIG;
> + name += len;
> + if (*name == ',')
> + name++;
> + }
>  
>   /* Allocate new major number for binderfs. */
>   ret = alloc_chrdev_region(_dev, 0, BINDERFS_MAX_MINOR,
> -- 
> 2.22.0.770.g0f2c4a37fd-goog
> 
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v8 07/24] erofs: add directory operations

2019-08-15 Thread Gao Xiang
Hi Linus,

On Thu, Aug 15, 2019 at 09:13:19AM -0700, Linus Torvalds wrote:
> On Wed, Aug 14, 2019 at 9:42 PM Gao Xiang  wrote:
> >
> > +
> > +static const unsigned char erofs_filetype_table[EROFS_FT_MAX] = {
> > +   [EROFS_FT_UNKNOWN]  = DT_UNKNOWN,
> > +   [EROFS_FT_REG_FILE] = DT_REG,
> > +   [EROFS_FT_DIR]  = DT_DIR,
> > +   [EROFS_FT_CHRDEV]   = DT_CHR,
> > +   [EROFS_FT_BLKDEV]   = DT_BLK,
> > +   [EROFS_FT_FIFO] = DT_FIFO,
> > +   [EROFS_FT_SOCK] = DT_SOCK,
> > +   [EROFS_FT_SYMLINK]  = DT_LNK,
> > +};
> 
> Hmm.
> 
> The EROFS_FT_XYZ values seem to match the normal FT_XYZ values, and
> we've lately tried to just have filesystems use the standard ones
> instead of having a (pointless) duplicate conversion between the two.
> 
> And then you can use the common "fs_ftype_to_dtype()" to convert from
> FT_XYZ to DT_XYZ.
> 
> Maybe I'm missing something, and the EROFS_FT_x list actually differs
> from the normal FT_x list some way, but it would be good to not
> introduce another case of this in normal filesystems, just as we've
> been getting rid of them.
> 
> See for example commit e10892189428 ("ext2: use common file type conversion").

Yes, you're right. There is nothing different with DT_XYZ since
I followed what f2fs did when I wrote this place.

Actually, I noticed that patchset once in mailing list months ago
https://lore.kernel.org/r/20181023201952.GA15676@pathfinder/
but I didn't keep eyes on it (whether this patchset is merged or not...)

OK, let me fix that like other fses. Thanks for pointing out.

Thanks,
Gao Xiang

> 
>Linus
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v8 07/24] erofs: add directory operations

2019-08-15 Thread Linus Torvalds
On Wed, Aug 14, 2019 at 9:42 PM Gao Xiang  wrote:
>
> +
> +static const unsigned char erofs_filetype_table[EROFS_FT_MAX] = {
> +   [EROFS_FT_UNKNOWN]  = DT_UNKNOWN,
> +   [EROFS_FT_REG_FILE] = DT_REG,
> +   [EROFS_FT_DIR]  = DT_DIR,
> +   [EROFS_FT_CHRDEV]   = DT_CHR,
> +   [EROFS_FT_BLKDEV]   = DT_BLK,
> +   [EROFS_FT_FIFO] = DT_FIFO,
> +   [EROFS_FT_SOCK] = DT_SOCK,
> +   [EROFS_FT_SYMLINK]  = DT_LNK,
> +};

Hmm.

The EROFS_FT_XYZ values seem to match the normal FT_XYZ values, and
we've lately tried to just have filesystems use the standard ones
instead of having a (pointless) duplicate conversion between the two.

And then you can use the common "fs_ftype_to_dtype()" to convert from
FT_XYZ to DT_XYZ.

Maybe I'm missing something, and the EROFS_FT_x list actually differs
from the normal FT_x list some way, but it would be good to not
introduce another case of this in normal filesystems, just as we've
been getting rid of them.

See for example commit e10892189428 ("ext2: use common file type conversion").

   Linus
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 04/22] media: Move v4l2_fwnode_parse_link from v4l2 to driver base

2019-08-15 Thread Steve Longerbeam




On 8/14/19 4:15 PM, Russell King - ARM Linux admin wrote:

On Wed, Aug 14, 2019 at 04:00:30PM -0700, Steve Longerbeam wrote:


On 8/14/19 3:04 PM, Russell King - ARM Linux admin wrote:

On Wed, Aug 14, 2019 at 12:04:41PM -0700, Steve Longerbeam wrote:

On 8/14/19 3:30 AM, Russell King - ARM Linux admin wrote:

On Tue, Aug 06, 2019 at 09:53:41AM -0700, Steve Longerbeam wrote:

The full patchset doesn't seem to be up yet, but see [1] for the cover
letter.

Was the entire series copied to the mailing lists, or just selected
patches?  I only saw 4, 9, 11 and 13-22 via lakml.

The whole series was posted to the linux-media ML, see [1]. At the time,
none of the linux-media ML archives had the whole series.


In the absence of the other patches, will this solve imx-media binding
the internal subdevs of sensor devices to the CSI2 interface?

"internal subdevs of sensor devices" ?? That doesn't make any sense.

Sorry, but it makes complete sense when you consider that sensor
devices may have more than one subdev, but there should be only one
that is the "output" to whatever the camera is attached to.  The
other subdevs are internal to the sensor.

Ah, thanks for the clarification. Yes, by "internal subdevs" I understand
what you mean now. The adv748x and smiapp are examples.


subdevs are not purely the remit of SoC drivers.

So there is no binding of internal subdevs to the receiver CSI-2. The
receiver CSI-2 subdev will create media links to the subdev that has an
externally exposed fwnode endpoint that connects with the CSI-2 sink pad.

Maybe - with 5.2, I get:

- entity 15: imx6-mipi-csi2 (5 pads, 6 links)
  type V4L2 subdev subtype Unknown flags 0
  device node name /dev/v4l-subdev2
 pad0: Sink
...
 <- "imx219 0-0010":0 []
 <- "imx219 pixel 0-0010":0 []

Adding some debug in gives:

[   11.963362] imx-media: imx_media_create_of_links() for imx6-mipi-csi2
[   11.963396] imx-media: create_of_link(): 
/soc/aips-bus@200/iomuxc-gpr@20e/ipu1_csi0_mux
[   11.963422] imx-media: create_of_link(): /soc/ipu@240
[   11.963450] imx-media: create_of_link(): /soc/ipu@280
[   11.963478] imx-media: create_of_link(): 
/soc/aips-bus@200/iomuxc-gpr@20e/ipu2_csi1_mux
[   11.963489] imx-media: imx6-mipi-csi2:4 -> ipu2_csi1_mux:0
[   11.963522] imx-media: create_of_link(): 
/soc/aips-bus@210/i2c@21a/camera@10
[   11.963533] imx-media: imx219 0-0010:0 -> imx6-mipi-csi2:0
[   11.963549] imx-media: imx_media_create_of_links() for imx219 pixel 0-0010
[   11.963577] imx-media: create_of_link(): /soc/aips-bus@210/mipi@21dc000
[   11.963587] imx-media: imx219 pixel 0-0010:0 -> imx6-mipi-csi2:0
[   11.963602] imx-media: imx_media_create_of_links() for imx219 0-0010

Note that it's not created by imx6-mipi-csi2, but by imx-media delving
around in the imx219 subdevs.

 From what I can see, smiapp does the same thing that I do in imx219 -
sets the subdev->dev member to point at the struct device, which then
means that v4l2_device_register_subdev() will associate the same fwnode
with both "imx219 pixel 0-0010" and "imx219 0-0010".


Ok, understood.

I realize imx_media_create_of_link() is a bit intrusive, and that's one 
of the things I'm trying to get rid of in this patchset. Unfortunately 
it's there for a reason which is described in patch 0021. But to explain 
here, the imx6-mipi-csi2 receiver outputs its four virtual channels on 
four separate source pads, and those connect to four different 
subdevices (video mux's and CSI's), and the problem is that only the 
first subdev that adds imx6-mipi-csi2 to its notifier asd list will get 
a notifier bind() callback (where links can be created to 
imx6-mipi-csi2) -- the other subdevs don't contain it in their asd lists 
so they never create the links to imx6-mipi-csi2. So until the 
requirement in v4l2-async that no notifiers can contain the same asd in 
its list is relaxed, this function will have to remain, but I can make 
it less intrusive (only create the missing links from imx6-mipi-csi2). 
I'm not able to find a cleaner workaround at the moment.


Steve

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[RFC PATCH 10/15] drivers/acrn: add interrupt injection support

2019-08-15 Thread Zhao Yakui
After ACRN devicemodel finishes the emulation of trapped MMIO/IO/PCICFG
access, it needs to inject one interrupt to notify that the guest can be
resumed.
IC_SET_IRQLINE: This is used to inject virtual IOAPIC gsi interrupt
IC_INJECT_MSI: Inject virtual MSI interrupt to guest OS
IC_VM_INTR_MONITOR: monitor the interrupt info for one guest OS

Co-developed-by: Jason Chen CJ 
Signed-off-by: Jason Chen CJ 
Co-developed-by: Mingqiang Chi 
Signed-off-by: Mingqiang Chi 
Signed-off-by: Zhao Yakui 
---
 drivers/staging/acrn/acrn_dev.c   | 48 +++
 drivers/staging/acrn/acrn_vm_mngt.c   | 28 ++
 include/linux/acrn/acrn_drv.h | 12 
 include/uapi/linux/acrn/acrn_ioctl_defs.h | 18 
 4 files changed, 106 insertions(+)

diff --git a/drivers/staging/acrn/acrn_dev.c b/drivers/staging/acrn/acrn_dev.c
index 28bbd78..1476817 100644
--- a/drivers/staging/acrn/acrn_dev.c
+++ b/drivers/staging/acrn/acrn_dev.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -316,6 +317,53 @@ long acrn_dev_ioctl(struct file *filep,
break;
}
 
+   case IC_SET_IRQLINE: {
+   ret = hcall_set_irqline(vm->vmid, ioctl_param);
+   if (ret < 0) {
+   pr_err("acrn: failed to set irqline!\n");
+   return -EFAULT;
+   }
+   break;
+   }
+
+   case IC_INJECT_MSI: {
+   struct acrn_msi_entry *msi;
+
+   msi = kmalloc(sizeof(*msi), GFP_KERNEL);
+   if (!msi)
+   return -ENOMEM;
+
+   if (copy_from_user(msi, (void *)ioctl_param, sizeof(*msi))) {
+   kfree(msi);
+   return -EFAULT;
+   }
+
+   ret = hcall_inject_msi(vm->vmid, virt_to_phys(msi));
+   kfree(msi);
+   if (ret < 0) {
+   pr_err("acrn: failed to inject!\n");
+   return -EFAULT;
+   }
+   break;
+   }
+
+   case IC_VM_INTR_MONITOR: {
+   struct page *page;
+
+   ret = get_user_pages_fast(ioctl_param, 1, 1, );
+   if (unlikely(ret != 1) || !page) {
+   pr_err("acrn-dev: failed to pin intr hdr buffer!\n");
+   return -ENOMEM;
+   }
+
+   ret = hcall_vm_intr_monitor(vm->vmid, page_to_phys(page));
+   if (ret < 0) {
+   pr_err("acrn-dev: monitor intr data err=%ld\n", ret);
+   return -EFAULT;
+   }
+   break;
+   }
+
default:
pr_warn("Unknown IOCTL 0x%x\n", ioctl_num);
ret = -EFAULT;
diff --git a/drivers/staging/acrn/acrn_vm_mngt.c 
b/drivers/staging/acrn/acrn_vm_mngt.c
index 9c6dd6d..4287595 100644
--- a/drivers/staging/acrn/acrn_vm_mngt.c
+++ b/drivers/staging/acrn/acrn_vm_mngt.c
@@ -11,8 +11,10 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
 
 #include "acrn_hypercall.h"
 #include "acrn_drv_internal.h"
@@ -72,3 +74,29 @@ int acrn_vm_destroy(struct acrn_vm *vm)
vm->vmid = ACRN_INVALID_VMID;
return 0;
 }
+
+int acrn_inject_msi(unsigned short vmid, unsigned long msi_addr,
+   unsigned long msi_data)
+{
+   struct acrn_msi_entry *msi;
+   int ret;
+
+   msi = kzalloc(sizeof(*msi), GFP_KERNEL);
+
+   if (!msi)
+   return -ENOMEM;
+
+   /* msi_addr: addr[19:12] with dest vcpu id */
+   /* msi_data: data[7:0] with vector */
+   msi->msi_addr = msi_addr;
+   msi->msi_data = msi_data;
+   ret = hcall_inject_msi(vmid, virt_to_phys(msi));
+   kfree(msi);
+   if (ret < 0) {
+   pr_err("acrn: failed to inject MSI for vmid %d, msi_addr %lx 
msi_data%lx!\n",
+  vmid, msi_addr, msi_data);
+   return -EFAULT;
+   }
+   return 0;
+}
+EXPORT_SYMBOL_GPL(acrn_inject_msi);
diff --git a/include/linux/acrn/acrn_drv.h b/include/linux/acrn/acrn_drv.h
index 62b03f0..bcdfcaf 100644
--- a/include/linux/acrn/acrn_drv.h
+++ b/include/linux/acrn/acrn_drv.h
@@ -83,4 +83,16 @@ extern int acrn_del_memory_region(unsigned short vmid, 
unsigned long gpa,
 extern int acrn_write_protect_page(unsigned short vmid, unsigned long gpa,
   unsigned char set);
 
+/**
+ * acrn_inject_msi() - inject MSI interrupt to guest
+ *
+ * @vmid: guest vmid
+ * @msi_addr: MSI addr matches MSI spec
+ * @msi_data: MSI data matches MSI spec
+ *
+ * Return: 0 on success, <0 on error
+ */
+extern int acrn_inject_msi(unsigned short vmid, unsigned long msi_addr,
+  unsigned long msi_data);
+
 #endif
diff --git a/include/uapi/linux/acrn/acrn_ioctl_defs.h 
b/include/uapi/linux/acrn/acrn_ioctl_defs.h
index ee259c2..371904c 100644
--- 

[RFC PATCH 14/15] drivers/acrn: add the support of irqfd and eventfd

2019-08-15 Thread Zhao Yakui
The ioventfd/irqfd based on eventfd is one mechanism that is widely used
to implement virtio kernel backend driver. After the ioreq is trigged from
virtio front driver, the eventfd_signal is called to notify the eventfd so
that the virtio kernel backend driver is waked up to handle the request.
After it is done, it will wake up the irqfd to inject the interrupt to
virtio front driver.

Each ioeventfd registered by userspace can map a PIO/MMIO range of the
guest to eventfd, and response to signal the eventfd when get the
in-range IO write from guest. Then the other side of eventfd can be
notified to process the IO request.

As we only use the ioeventfd to listen virtqueue's kick register, some
limitations are added:
  1) Length support can only be 1, 2, 4 or 8
  2) Only support write operation, read will get 0
  3) Same address, shorter length writing can be handled with the
 integral data matching

The irqfd based on eventfd provides a pipe for injecting guest interrupt
through a file description writing operation. Each irqfd registered by
userspace can map a interrupt of the guest to eventfd, and a writing
operation on one side of the eventfd will trigger the interrupt injection
on acrn_hsm side.

Co-developed-by: Shuo Liu 
Signed-off-by: Shuo Liu 
Signed-off-by: Zhao Yakui 
---
 drivers/staging/acrn/Makefile |   4 +-
 drivers/staging/acrn/acrn_dev.c   |  19 ++
 drivers/staging/acrn/acrn_drv_internal.h  |  10 +
 drivers/staging/acrn/acrn_ioeventfd.c | 407 ++
 drivers/staging/acrn/acrn_irqfd.c | 339 +
 drivers/staging/acrn/acrn_vm_mngt.c   |   9 +-
 include/uapi/linux/acrn/acrn_ioctl_defs.h |  25 ++
 7 files changed, 811 insertions(+), 2 deletions(-)
 create mode 100644 drivers/staging/acrn/acrn_ioeventfd.c
 create mode 100644 drivers/staging/acrn/acrn_irqfd.c

diff --git a/drivers/staging/acrn/Makefile b/drivers/staging/acrn/Makefile
index a381944..f8d8ee2 100644
--- a/drivers/staging/acrn/Makefile
+++ b/drivers/staging/acrn/Makefile
@@ -4,4 +4,6 @@ acrn-y := acrn_dev.o \
  acrn_vm_mngt.o \
  acrn_mm.o \
  acrn_mm_hugetlb.o \
- acrn_ioreq.o
+ acrn_ioreq.o  \
+ acrn_ioeventfd.o \
+ acrn_irqfd.o
diff --git a/drivers/staging/acrn/acrn_dev.c b/drivers/staging/acrn/acrn_dev.c
index ef0ec50..0602125 100644
--- a/drivers/staging/acrn/acrn_dev.c
+++ b/drivers/staging/acrn/acrn_dev.c
@@ -141,6 +141,8 @@ long acrn_dev_ioctl(struct file *filep,
if (ret < 0)
goto ioreq_buf_fail;
 
+   acrn_ioeventfd_init(vm->vmid);
+   acrn_irqfd_init(vm->vmid);
pr_info("acrn: VM %d created\n", created_vm->vmid);
kfree(created_vm);
break;
@@ -506,6 +508,23 @@ long acrn_dev_ioctl(struct file *filep,
 
break;
}
+   case IC_EVENT_IOEVENTFD: {
+   struct acrn_ioeventfd args;
+
+   if (copy_from_user(, (void *)ioctl_param, sizeof(args)))
+   return -EFAULT;
+   ret = acrn_ioeventfd_config(vm->vmid, );
+   break;
+   }
+
+   case IC_EVENT_IRQFD: {
+   struct acrn_irqfd args;
+
+   if (copy_from_user(, (void *)ioctl_param, sizeof(args)))
+   return -EFAULT;
+   ret = acrn_irqfd_config(vm->vmid, );
+   break;
+   }
 
default:
pr_warn("Unknown IOCTL 0x%x\n", ioctl_num);
diff --git a/drivers/staging/acrn/acrn_drv_internal.h 
b/drivers/staging/acrn/acrn_drv_internal.h
index 7813387..b9ded9a 100644
--- a/drivers/staging/acrn/acrn_drv_internal.h
+++ b/drivers/staging/acrn/acrn_drv_internal.h
@@ -173,4 +173,14 @@ void acrn_ioreq_driver_init(void);
 void acrn_ioreq_clear_request(struct acrn_vm *vm);
 int acrn_ioreq_distribute_request(struct acrn_vm *vm);
 
+/* ioeventfd APIs */
+int acrn_ioeventfd_init(unsigned short vmid);
+int acrn_ioeventfd_config(unsigned short vmid, struct acrn_ioeventfd *args);
+void acrn_ioeventfd_deinit(unsigned short vmid);
+
+/* irqfd APIs */
+int acrn_irqfd_init(unsigned short vmid);
+int acrn_irqfd_config(unsigned short vmid, struct acrn_irqfd *args);
+void acrn_irqfd_deinit(unsigned short vmid);
+
 #endif
diff --git a/drivers/staging/acrn/acrn_ioeventfd.c 
b/drivers/staging/acrn/acrn_ioeventfd.c
new file mode 100644
index 000..b330625
--- /dev/null
+++ b/drivers/staging/acrn/acrn_ioeventfd.c
@@ -0,0 +1,407 @@
+// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
+/*
+ * ACRN hyperviosr service module (SRV): ioeventfd based on eventfd
+ *
+ * Copyright (C) 2019 Intel Corporation. All rights reserved.
+ * Liu Shuo 
+ * Zhao Yakui 
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include "acrn_drv_internal.h"
+#include "acrn_hypercall.h"
+
+static 

[RFC PATCH 08/15] drivers/acrn: add VM memory management for ACRN char device

2019-08-15 Thread Zhao Yakui
In order to launch the ACRN guest system, it needs to setup the mapping
between GPA (guest physical address) and HPA (host physical address).
This is based on memory virtualization and configured in EPT table.
The ioctl related with memory management is added and then the hypercall
is called so that the ACRN hypervisor can help to setup the memory
mapping for ACRN guest.
The 1G/2M huge page is used to optimize the EPT table for guest VM. This
will simplify the memory allocation and also optimizes the TLB.
For the MMIO mapping: It can support 4K/2M page.

IC_SET_MEMSEG: This is used to setup the memory mapping for the memory
of guest system by using hugetlb(Guest physical address and host virtual
addr).It is also used to setup the device MMIO mapping for PCI device.
IC_UNSET_MEMSEG: This is used to remove the device MMIO mapping for PCI
device. This is used with updating the MMIO mapping together. As the
acrn hypervisor is mainly used for embedded IOT device, it doesn't support
the dynamica removal of memory mapping.

Co-developed-by: Jason Chen CJ 
Signed-off-by: Jason Chen CJ 
Co-developed-by: Li, Fei 
Signed-off-by: Li, Fei 
Co-developed-by: Liu Shuo 
Signed-off-by: Liu Shuo 
Signed-off-by: Zhao Yakui 
---
 drivers/staging/acrn/Makefile |   4 +-
 drivers/staging/acrn/acrn_dev.c   |  27 +++
 drivers/staging/acrn/acrn_drv_internal.h  |  90 +++---
 drivers/staging/acrn/acrn_mm.c| 227 
 drivers/staging/acrn/acrn_mm_hugetlb.c| 281 ++
 drivers/staging/acrn/acrn_vm_mngt.c   |   2 +
 include/linux/acrn/acrn_drv.h |  86 +
 include/uapi/linux/acrn/acrn_common_def.h |  25 +++
 include/uapi/linux/acrn/acrn_ioctl_defs.h |  41 +
 9 files changed, 759 insertions(+), 24 deletions(-)
 create mode 100644 drivers/staging/acrn/acrn_mm.c
 create mode 100644 drivers/staging/acrn/acrn_mm_hugetlb.c
 create mode 100644 include/linux/acrn/acrn_drv.h
 create mode 100644 include/uapi/linux/acrn/acrn_common_def.h

diff --git a/drivers/staging/acrn/Makefile b/drivers/staging/acrn/Makefile
index 426d6e8..ec62afe 100644
--- a/drivers/staging/acrn/Makefile
+++ b/drivers/staging/acrn/Makefile
@@ -1,4 +1,6 @@
 obj-$(CONFIG_ACRN_HSM) := acrn.o
 acrn-y := acrn_dev.o \
  acrn_hypercall.o \
- acrn_vm_mngt.o
+ acrn_vm_mngt.o \
+ acrn_mm.o \
+ acrn_mm_hugetlb.o
diff --git a/drivers/staging/acrn/acrn_dev.c b/drivers/staging/acrn/acrn_dev.c
index 7372316..cb62819 100644
--- a/drivers/staging/acrn/acrn_dev.c
+++ b/drivers/staging/acrn/acrn_dev.c
@@ -44,6 +44,7 @@ static
 int acrn_dev_open(struct inode *inodep, struct file *filep)
 {
struct acrn_vm *vm;
+   int i;
 
vm = kzalloc(sizeof(*vm), GFP_KERNEL);
if (!vm)
@@ -53,6 +54,10 @@ int acrn_dev_open(struct inode *inodep, struct file *filep)
vm->vmid = ACRN_INVALID_VMID;
vm->dev = acrn_device;
 
+   for (i = 0; i < HUGEPAGE_HLIST_ARRAY_SIZE; i++)
+   INIT_HLIST_HEAD(>hugepage_hlist[i]);
+   mutex_init(>hugepage_lock);
+
write_lock_bh(_vm_list_lock);
vm_list_add(>list);
write_unlock_bh(_vm_list_lock);
@@ -212,6 +217,28 @@ long acrn_dev_ioctl(struct file *filep,
return ret;
}
 
+   case IC_SET_MEMSEG: {
+   struct vm_memmap memmap;
+
+   if (copy_from_user(, (void *)ioctl_param,
+  sizeof(memmap)))
+   return -EFAULT;
+
+   ret = map_guest_memseg(vm, );
+   break;
+   }
+
+   case IC_UNSET_MEMSEG: {
+   struct vm_memmap memmap;
+
+   if (copy_from_user(, (void *)ioctl_param,
+  sizeof(memmap)))
+   return -EFAULT;
+
+   ret = unmap_guest_memseg(vm, );
+   break;
+   }
+
default:
pr_warn("Unknown IOCTL 0x%x\n", ioctl_num);
ret = -EFAULT;
diff --git a/drivers/staging/acrn/acrn_drv_internal.h 
b/drivers/staging/acrn/acrn_drv_internal.h
index 6758dea..5098765 100644
--- a/drivers/staging/acrn/acrn_drv_internal.h
+++ b/drivers/staging/acrn/acrn_drv_internal.h
@@ -11,6 +11,57 @@
 #include 
 #include 
 
+struct vm_memory_region {
+#define MR_ADD 0
+#define MR_DEL 2
+   u32 type;
+
+   /* IN: mem attr */
+   u32 prot;
+
+   /* IN: beginning guest GPA to map */
+   u64 gpa;
+
+   /* IN: VM0's GPA which foreign gpa will be mapped to */
+   u64 vm0_gpa;
+
+   /* IN: size of the region */
+   u64 size;
+};
+
+struct set_regions {
+   /*IN: vmid for this hypercall */
+   u16 vmid;
+
+   /** Reserved */
+   u16 reserved[3];
+
+   /* IN: multi memmaps numbers */
+   u32 mr_num;
+
+   /** Reserved */
+   u32 reserved1;
+   /* IN:
+* the gpa of memmaps buffer, point to the memmaps array:
+* struct 

[RFC PATCH 12/15] drivers/acrn: add driver-specific IRQ handle to dispatch IO_REQ request

2019-08-15 Thread Zhao Yakui
After ACRN hypervisor captures the io_request(mmio, IO, PCI access) from
guest OS, it will send the IRQ interrupt to SOS system.
The HYPERVISOR_CALLBACK_VECTOR ISR handler will be executed and it
needs to call the driver-specific ISR handler to dispatch emulated
io_request.
After the emulation of ioreq request is finished, the ACRN hypervisor
is notified and then can resume the execution of guest OS.

Co-developed-by: Jason Chen CJ 
Signed-off-by: Jason Chen CJ 
Co-developed-by: Mingqiang Chi 
Signed-off-by: Mingqiang Chi 
Co-developed-by: Liu Shuo 
Signed-off-by: Liu Shuo 
Signed-off-by: Zhao Yakui 
---
 drivers/staging/acrn/acrn_dev.c | 41 +
 1 file changed, 41 insertions(+)

diff --git a/drivers/staging/acrn/acrn_dev.c b/drivers/staging/acrn/acrn_dev.c
index 28258fb..93f45e3 100644
--- a/drivers/staging/acrn/acrn_dev.c
+++ b/drivers/staging/acrn/acrn_dev.c
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -41,6 +42,7 @@ static intacrn_hsm_inited;
 static int major;
 static struct class*acrn_class;
 static struct device   *acrn_device;
+static struct tasklet_struct acrn_io_req_tasklet;
 
 static
 int acrn_dev_open(struct inode *inodep, struct file *filep)
@@ -416,6 +418,16 @@ long acrn_dev_ioctl(struct file *filep,
break;
}
case IC_CLEAR_VM_IOREQ: {
+   /*
+* we need to flush the current pending ioreq dispatch
+* tasklet and finish it before clearing all ioreq of this VM.
+* With tasklet_kill, there still be a very rare race which
+* might lost one ioreq tasklet for other VMs. So arm one after
+* the clearing. It's harmless.
+*/
+   tasklet_schedule(_io_req_tasklet);
+   tasklet_kill(_io_req_tasklet);
+   tasklet_schedule(_io_req_tasklet);
acrn_ioreq_clear_request(vm);
break;
}
@@ -449,6 +461,28 @@ static int acrn_dev_release(struct inode *inodep, struct 
file *filep)
return 0;
 }
 
+static void io_req_tasklet(unsigned long data)
+{
+   struct acrn_vm *vm;
+   /* This is already in tasklet. Use read_lock for list_lock */
+
+   read_lock(_vm_list_lock);
+   list_for_each_entry(vm, _vm_list, list) {
+   if (!vm || !vm->req_buf)
+   break;
+
+   get_vm(vm);
+   acrn_ioreq_distribute_request(vm);
+   put_vm(vm);
+   }
+   read_unlock(_vm_list_lock);
+}
+
+static void acrn_intr_handler(void)
+{
+   tasklet_schedule(_io_req_tasklet);
+}
+
 static const struct file_operations fops = {
.open = acrn_dev_open,
.release = acrn_dev_release,
@@ -462,6 +496,7 @@ static const struct file_operations fops = {
 
 static int __init acrn_init(void)
 {
+   unsigned long flag;
struct api_version *api_version;
acrn_hsm_inited = 0;
if (x86_hyper_type != X86_HYPER_ACRN)
@@ -518,6 +553,10 @@ static int __init acrn_init(void)
return PTR_ERR(acrn_device);
}
 
+   tasklet_init(_io_req_tasklet, io_req_tasklet, 0);
+   local_irq_save(flag);
+   acrn_setup_intr_irq(acrn_intr_handler);
+   local_irq_restore(flag);
acrn_ioreq_driver_init();
pr_info("acrn: ACRN Hypervisor service module initialized\n");
acrn_hsm_inited = 1;
@@ -529,6 +568,8 @@ static void __exit acrn_exit(void)
if (!acrn_hsm_inited)
return;
 
+   tasklet_kill(_io_req_tasklet);
+   acrn_remove_intr_irq();
device_destroy(acrn_class, MKDEV(major, 0));
class_unregister(acrn_class);
class_destroy(acrn_class);
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[RFC PATCH 04/15] drivers/acrn: add the basic framework of acrn char device driver

2019-08-15 Thread Zhao Yakui
ACRN hypervisor service module is the important middle layer that allows
the Linux kernel to communicate with the ACRN hypervisor. It includes
the management of virtualized CPU/memory/device/interrupt for other ACRN
guest. The user-space applications can use the provided ACRN ioctls to
interact with ACRN hypervisor through different hypercalls.

Add one basic framework firstly and the following patches will
add the corresponding implementations, which includes the management of
virtualized CPU/memory/interrupt and the emulation of MMIO/IO/PCI access.
The device file of /dev/acrn_hsm can be accessed in user-space to
communicate with ACRN module.

Co-developed-by: Jason Chen CJ 
Signed-off-by: Jason Chen CJ 
Co-developed-by: Jack Ren 
Signed-off-by: Jack Ren 
Co-developed-by: Mingqiang Chi 
Signed-off-by: Mingqiang Chi 
Co-developed-by: Liu Shuo 
Signed-off-by: Liu Shuo 
Signed-off-by: Zhao Yakui 
---
 drivers/staging/Kconfig |   2 +
 drivers/staging/Makefile|   1 +
 drivers/staging/acrn/Kconfig|  18 ++
 drivers/staging/acrn/Makefile   |   2 +
 drivers/staging/acrn/acrn_dev.c | 123 
 5 files changed, 146 insertions(+)
 create mode 100644 drivers/staging/acrn/Kconfig
 create mode 100644 drivers/staging/acrn/Makefile
 create mode 100644 drivers/staging/acrn/acrn_dev.c

diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index 7c96a01..0766de5 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -120,4 +120,6 @@ source "drivers/staging/kpc2000/Kconfig"
 
 source "drivers/staging/isdn/Kconfig"
 
+source "drivers/staging/acrn/Kconfig"
+
 endif # STAGING
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index fcaac96..f927eb0 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -49,4 +49,5 @@ obj-$(CONFIG_XIL_AXIS_FIFO)   += axis-fifo/
 obj-$(CONFIG_EROFS_FS) += erofs/
 obj-$(CONFIG_FIELDBUS_DEV) += fieldbus/
 obj-$(CONFIG_KPC2000)  += kpc2000/
+obj-$(CONFIG_ACRN_HSM) += acrn/
 obj-$(CONFIG_ISDN_CAPI)+= isdn/
diff --git a/drivers/staging/acrn/Kconfig b/drivers/staging/acrn/Kconfig
new file mode 100644
index 000..a047d5f
--- /dev/null
+++ b/drivers/staging/acrn/Kconfig
@@ -0,0 +1,18 @@
+config ACRN_HSM
+   tristate "Intel ACRN Hypervisor service Module"
+   depends on ACRN_GUEST
+   depends on HUGETLBFS
+   depends on PCI_MSI
+   default n
+   help
+ This is the Hypervisor service Module (ACRN.ko) for ACRN guest
+ to communicate with ACRN hypervisor. It includes the management
+ of virtualized CPU/memory/device/interrupt for other ACRN guest.
+
+ It is required if it needs to manage other ACRN guests. User-guest
+ OS does not need it.
+
+ If unsure, say N.
+ If you wish to work on this driver, to help improve it, or to
+ report problems you have with them, please use the
+ acrn-...@lists.projectacrn.org mailing list.
diff --git a/drivers/staging/acrn/Makefile b/drivers/staging/acrn/Makefile
new file mode 100644
index 000..48fca38
--- /dev/null
+++ b/drivers/staging/acrn/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_ACRN_HSM) := acrn.o
+acrn-y := acrn_dev.o
diff --git a/drivers/staging/acrn/acrn_dev.c b/drivers/staging/acrn/acrn_dev.c
new file mode 100644
index 000..55a7612
--- /dev/null
+++ b/drivers/staging/acrn/acrn_dev.c
@@ -0,0 +1,123 @@
+// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
+/*
+ * ACRN hyperviosr service module (HSM): main framework
+ *
+ * Copyright (C) 2019 Intel Corporation. All rights reserved.
+ *
+ * Jason Chen CJ 
+ * Zhao Yakui 
+ * Jack Ren 
+ * Mingqiang Chi 
+ * Liu Shuo 
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define  DEVICE_NAME "acrn_hsm"
+#define  CLASS_NAME  "acrn"
+
+static int acrn_hsm_inited;
+static int major;
+static struct class*acrn_class;
+static struct device   *acrn_device;
+
+static
+int acrn_dev_open(struct inode *inodep, struct file *filep)
+{
+   pr_info("%s: opening device node\n", __func__);
+
+   return 0;
+}
+
+static
+long acrn_dev_ioctl(struct file *filep,
+   unsigned int ioctl_num, unsigned long ioctl_param)
+{
+   long ret = 0;
+
+   return ret;
+}
+
+static int acrn_dev_release(struct inode *inodep, struct file *filep)
+{
+   return 0;
+}
+
+static const struct file_operations fops = {
+   .open = acrn_dev_open,
+   .release = acrn_dev_release,
+   .unlocked_ioctl = acrn_dev_ioctl,
+};
+
+#define EAX_PRIVILEGE_VM   BIT(0)
+
+static int __init acrn_init(void)
+{
+   acrn_hsm_inited = 0;
+   if (x86_hyper_type != X86_HYPER_ACRN)
+   return -ENODEV;
+
+   if (!(cpuid_eax(0x4001) & EAX_PRIVILEGE_VM))
+   return -EPERM;
+
+   /* Try to dynamically allocate a major number for the device */
+   major = 

[RFC PATCH 09/15] drivers/acrn: add passthrough device support

2019-08-15 Thread Zhao Yakui
Pass-through device plays an important role for guest OS when it is
accessed exclusively by guest OS. This is critical for the performance
scenario. After one PCI device is assigned to guest OS, it can be
accessed exclusively by guest system. It can avoid the device emulation
and provide the better performance.
It provides the following operations for supporting pass-through device.
- assign, pass-through device
   ACRN_ASSIGN_PTDEV: Assign one PCI device to one guest OS
- deassign pass-through device
   ACRN_DEASSIGN_PTDEV: Return the assigned PCI device from
the guest OS so that it can be assigned to another guest OS.
- set, reset pass-through device intr info
   ACRN_SET_PTDEV_INTR_INFO
   ACRN_RESET_PTDEV_INTR_INFO : This is used to configure
the interrupt info for the assigned pass-through device so that
ACRN hypervisor can inject the interrupt into guest system after
the device interrupt is triggered.

Co-developed-by: Gao, Shiqing 
Signed-off-by: Gao, Shiqing 
Co-developed-by: Jason Chen CJ 
Signed-off-by: Jason Chen CJ 
Signed-off-by: Zhao Yakui 
---
 drivers/staging/acrn/acrn_dev.c   | 77 +++
 drivers/staging/acrn/acrn_drv_internal.h  | 25 ++
 include/uapi/linux/acrn/acrn_ioctl_defs.h | 47 +++
 3 files changed, 149 insertions(+)

diff --git a/drivers/staging/acrn/acrn_dev.c b/drivers/staging/acrn/acrn_dev.c
index cb62819..28bbd78 100644
--- a/drivers/staging/acrn/acrn_dev.c
+++ b/drivers/staging/acrn/acrn_dev.c
@@ -239,6 +239,83 @@ long acrn_dev_ioctl(struct file *filep,
break;
}
 
+   case IC_ASSIGN_PTDEV: {
+   unsigned short bdf;
+
+   if (copy_from_user(, (void *)ioctl_param,
+  sizeof(unsigned short)))
+   return -EFAULT;
+
+   ret = hcall_assign_ptdev(vm->vmid, bdf);
+   if (ret < 0) {
+   pr_err("acrn: failed to assign ptdev!\n");
+   return -EFAULT;
+   }
+   break;
+   }
+   case IC_DEASSIGN_PTDEV: {
+   unsigned short bdf;
+
+   if (copy_from_user(, (void *)ioctl_param,
+  sizeof(unsigned short)))
+   return -EFAULT;
+
+   ret = hcall_deassign_ptdev(vm->vmid, bdf);
+   if (ret < 0) {
+   pr_err("acrn: failed to deassign ptdev!\n");
+   return -EFAULT;
+   }
+   break;
+   }
+
+   case IC_SET_PTDEV_INTR_INFO: {
+   struct ic_ptdev_irq ic_pt_irq;
+   struct hc_ptdev_irq *hc_pt_irq;
+
+   if (copy_from_user(_pt_irq, (void *)ioctl_param,
+  sizeof(ic_pt_irq)))
+   return -EFAULT;
+
+   hc_pt_irq = kmalloc(sizeof(*hc_pt_irq), GFP_KERNEL);
+   if (!hc_pt_irq)
+   return -ENOMEM;
+
+   memcpy(hc_pt_irq, _pt_irq, sizeof(*hc_pt_irq));
+
+   ret = hcall_set_ptdev_intr_info(vm->vmid,
+   virt_to_phys(hc_pt_irq));
+   kfree(hc_pt_irq);
+   if (ret < 0) {
+   pr_err("acrn: failed to set intr info for ptdev!\n");
+   return -EFAULT;
+   }
+
+   break;
+   }
+   case IC_RESET_PTDEV_INTR_INFO: {
+   struct ic_ptdev_irq ic_pt_irq;
+   struct hc_ptdev_irq *hc_pt_irq;
+
+   if (copy_from_user(_pt_irq, (void *)ioctl_param,
+  sizeof(ic_pt_irq)))
+   return -EFAULT;
+
+   hc_pt_irq = kmalloc(sizeof(*hc_pt_irq), GFP_KERNEL);
+   if (!hc_pt_irq)
+   return -ENOMEM;
+
+   memcpy(hc_pt_irq, _pt_irq, sizeof(*hc_pt_irq));
+
+   ret = hcall_reset_ptdev_intr_info(vm->vmid,
+ virt_to_phys(hc_pt_irq));
+   kfree(hc_pt_irq);
+   if (ret < 0) {
+   pr_err("acrn: failed to reset intr info for ptdev!\n");
+   return -EFAULT;
+   }
+   break;
+   }
+
default:
pr_warn("Unknown IOCTL 0x%x\n", ioctl_num);
ret = -EFAULT;
diff --git a/drivers/staging/acrn/acrn_drv_internal.h 
b/drivers/staging/acrn/acrn_drv_internal.h
index 5098765..3e633cd 100644
--- a/drivers/staging/acrn/acrn_drv_internal.h
+++ b/drivers/staging/acrn/acrn_drv_internal.h
@@ -115,4 +115,29 @@ void hugepage_free_guest(struct acrn_vm *vm);
 void *hugepage_map_guest_phys(struct acrn_vm *vm, u64 guest_phys, size_t size);
 int hugepage_unmap_guest_phys(struct acrn_vm *vm, u64 guest_phys);
 int set_memory_regions(struct set_regions *regions);
+
+struct hc_ptdev_irq {
+#define IRQ_INTX 0
+#define IRQ_MSI 1
+#define 

[RFC PATCH 13/15] drivers/acrn: add service to obtain Power data transition

2019-08-15 Thread Zhao Yakui
The px/cx data is critical to support the power transition. DM will get
these data to build DSDT for UOS. With this DSDT, UOS would have the
capability on power control if acpi-cpufreq/idle driver is enabled in
kernel.
Add the PM ioctl that is used to obtain the info of power state
so that the DM can construct the DSDT with Power frequence/C-state idle
for guest system.

Co-developed-by: Jason Chen CJ 
Signed-off-by: Jason Chen CJ 
Co-developed-by: Victor Sun 
Signed-off-by: Victor Sun 
Signed-off-by: Zhao Yakui 
---
 drivers/staging/acrn/acrn_dev.c   | 75 +++
 include/uapi/linux/acrn/acrn_ioctl_defs.h | 36 +++
 2 files changed, 111 insertions(+)

diff --git a/drivers/staging/acrn/acrn_dev.c b/drivers/staging/acrn/acrn_dev.c
index 93f45e3..ef0ec50 100644
--- a/drivers/staging/acrn/acrn_dev.c
+++ b/drivers/staging/acrn/acrn_dev.c
@@ -432,6 +432,81 @@ long acrn_dev_ioctl(struct file *filep,
break;
}
 
+   case IC_PM_GET_CPU_STATE: {
+   u64 cmd;
+
+   if (copy_from_user(, (void *)ioctl_param, sizeof(cmd)))
+   return -EFAULT;
+
+   switch (cmd & PMCMD_TYPE_MASK) {
+   case PMCMD_GET_PX_CNT:
+   case PMCMD_GET_CX_CNT: {
+   u64 *pm_info;
+
+   pm_info = kmalloc(sizeof(u64), GFP_KERNEL);
+   if (!pm_info)
+   return -ENOMEM;
+
+   ret = hcall_get_cpu_state(cmd, virt_to_phys(pm_info));
+   if (ret < 0) {
+   kfree(pm_info);
+   return -EFAULT;
+   }
+
+   if (copy_to_user((void *)ioctl_param,
+pm_info, sizeof(u64)))
+   ret = -EFAULT;
+
+   kfree(pm_info);
+   break;
+   }
+   case PMCMD_GET_PX_DATA: {
+   struct cpu_px_data *px_data;
+
+   px_data = kmalloc(sizeof(*px_data), GFP_KERNEL);
+   if (!px_data)
+   return -ENOMEM;
+
+   ret = hcall_get_cpu_state(cmd, virt_to_phys(px_data));
+   if (ret < 0) {
+   kfree(px_data);
+   return -EFAULT;
+   }
+
+   if (copy_to_user((void *)ioctl_param,
+px_data, sizeof(*px_data)))
+   ret = -EFAULT;
+
+   kfree(px_data);
+   break;
+   }
+   case PMCMD_GET_CX_DATA: {
+   struct cpu_cx_data *cx_data;
+
+   cx_data = kmalloc(sizeof(*cx_data), GFP_KERNEL);
+   if (!cx_data)
+   return -ENOMEM;
+
+   ret = hcall_get_cpu_state(cmd, virt_to_phys(cx_data));
+   if (ret < 0) {
+   kfree(cx_data);
+   return -EFAULT;
+   }
+
+   if (copy_to_user((void *)ioctl_param,
+cx_data, sizeof(*cx_data)))
+   ret = -EFAULT;
+   kfree(cx_data);
+   break;
+   }
+   default:
+   ret = -EFAULT;
+   break;
+   }
+
+   break;
+   }
+
default:
pr_warn("Unknown IOCTL 0x%x\n", ioctl_num);
ret = -EFAULT;
diff --git a/include/uapi/linux/acrn/acrn_ioctl_defs.h 
b/include/uapi/linux/acrn/acrn_ioctl_defs.h
index c3c4f98..c762bd2 100644
--- a/include/uapi/linux/acrn/acrn_ioctl_defs.h
+++ b/include/uapi/linux/acrn/acrn_ioctl_defs.h
@@ -234,6 +234,39 @@ struct ioreq_notify {
uint32_t vcpu;
 };
 
+struct acrn_generic_address {
+   uint8_t space_id;
+   uint8_t bit_width;
+   uint8_t bit_offset;
+   uint8_t access_size;
+   uint64_taddress;
+};
+
+struct cpu_cx_data {
+   struct acrn_generic_address cx_reg;
+   uint8_t type;
+   uint32_tlatency;
+   uint64_tpower;
+};
+
+struct cpu_px_data {
+   uint64_t core_frequency;/* megahertz */
+   uint64_t power; /* milliWatts */
+   uint64_t transition_latency;/* microseconds */
+   uint64_t bus_master_latency;/* microseconds */
+   uint64_t control;   /* control value */
+   uint64_t status;/* success indicator */
+};
+
+#define PMCMD_TYPE_MASK0x00ff
+
+enum pm_cmd_type {
+   PMCMD_GET_PX_CNT,
+   PMCMD_GET_PX_DATA,
+   PMCMD_GET_CX_CNT,

[RFC PATCH 15/15] drivers/acrn: add the support of offline SOS cpu

2019-08-15 Thread Zhao Yakui
The ACRN-hypervisor works in partition mode. In such case the guest OS
and domain0 kernel will run in the different CPUs.  In course of booting
domain0 kernel, it can use all the available CPUs,which can accelerate
the booting. But after the booting is finished, it needs to offline the
other CPUs so that they can be allocated to the guest OS.

add sysfs with attr "offline_cpu", use
echo cpu_id > /sys/class/acrn/acrn_hsm/offline_cpu
to do the hypercall offline/destroy according vcpu.
before doing it, It will offline cpu by using the below cmd:
echo 0 > /sys/devices/system/cpu/cpuX/online

Currently this is mainly used in user-space device model before
booting other ACRN guest.

Co-developed-by: Jason Chen CJ 
Signed-off-by: Jason Chen CJ 
Signed-off-by: Zhao Yakui 
---
 drivers/staging/acrn/acrn_dev.c | 45 +
 1 file changed, 45 insertions(+)

diff --git a/drivers/staging/acrn/acrn_dev.c b/drivers/staging/acrn/acrn_dev.c
index 0602125..6868003 100644
--- a/drivers/staging/acrn/acrn_dev.c
+++ b/drivers/staging/acrn/acrn_dev.c
@@ -588,6 +588,41 @@ static const struct file_operations fops = {
 #define SUPPORT_HV_API_VERSION_MAJOR   1
 #define SUPPORT_HV_API_VERSION_MINOR   0
 
+static ssize_t
+offline_cpu_store(struct device *dev,
+   struct device_attribute *attr,
+   const char *buf, size_t count)
+{
+#ifdef CONFIG_X86
+   u64 cpu, lapicid;
+
+   if (kstrtoull(buf, 0, ) < 0)
+   return -EINVAL;
+
+   if (cpu_possible(cpu)) {
+   lapicid = cpu_data(cpu).apicid;
+   pr_info("acrn: try to offline cpu %lld with lapicid %lld\n",
+   cpu, lapicid);
+   if (hcall_sos_offline_cpu(lapicid) < 0) {
+   pr_err("acrn: failed to offline cpu from 
Hypervisor!\n");
+   return -EINVAL;
+   }
+   }
+#endif
+   return count;
+}
+
+static DEVICE_ATTR(offline_cpu, 00200, NULL, offline_cpu_store);
+
+static struct attribute *acrn_attrs[] = {
+   _attr_offline_cpu.attr,
+   NULL
+};
+
+static struct attribute_group acrn_attr_group = {
+   .attrs = acrn_attrs,
+};
+
 static int __init acrn_init(void)
 {
unsigned long flag;
@@ -647,6 +682,15 @@ static int __init acrn_init(void)
return PTR_ERR(acrn_device);
}
 
+   if (sysfs_create_group(_device->kobj, _attr_group)) {
+   pr_warn("acrn: sysfs create failed\n");
+   device_destroy(acrn_class, MKDEV(major, 0));
+   class_unregister(acrn_class);
+   class_destroy(acrn_class);
+   unregister_chrdev(major, DEVICE_NAME);
+   return -EINVAL;
+   }
+
tasklet_init(_io_req_tasklet, io_req_tasklet, 0);
local_irq_save(flag);
acrn_setup_intr_irq(acrn_intr_handler);
@@ -664,6 +708,7 @@ static void __exit acrn_exit(void)
 
tasklet_kill(_io_req_tasklet);
acrn_remove_intr_irq();
+   sysfs_remove_group(_device->kobj, _attr_group);
device_destroy(acrn_class, MKDEV(major, 0));
class_unregister(acrn_class);
class_destroy(acrn_class);
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[RFC PATCH 11/15] drivers/acrn: add the support of handling emulated ioreq

2019-08-15 Thread Zhao Yakui
After guest UOS is booted, the MMIO/IO access will cause that
it exits from VMX non-root env into ACRN hypervisor. Then the ACRN
hypervisor will inject virtual irq into the Linux guest with ACRN HSM
module. The ACRN_HSM handles this virtual irq (which is based on
HYPERVISOR_CALLBACK_VECTOR), parses corresponding IO request from shared
IOReq buffer and distributes it to different ioreq client. After the
ioreq emulation is finished, it will notify ACRN hypervisor and then
hypervisor will resume the execution of guest UOS.

ACRN HSM module will group some range of emulated MMIO/IO addr as
one ioreq_client. It will determine which ioreq_client should handle
the emulated MMIO/IO request based on the address and then dispatch it
into the ioreq_client thread. User-space device model will create one
default ioreq_client, which is used to handle the emulated MMIO/IO in
user-space thread.

Add ioreq service and defines IOReq APIs like below:
   int acrn_ioreq_create_client(unsigned long vmid,
ioreq_handler_t handler,
void *client_priv,
char *name);
   void acrn_ioreq_destroy_client(int client_id);
   int acrn_ioreq_add_iorange(int client_id, enum request_type type,
   long start, long end);
   int acrn_ioreq_del_iorange(int client_id, enum request_type type,
   long start, long end);
   struct acrn_request * acrn_ioreq_get_reqbuf(int client_id);
   int acrn_ioreq_attach_client(int client_id);
   int acrn_ioreq_complete_request(int client_id);

Co-developed-by: Jason Chen CJ 
Signed-off-by: Jason Chen CJ 
Co-developed-by: Yin FengWei 
Signed-off-by: Yin FengWei 
Co-developed-by: Liu Shuo 
Signed-off-by: Liu Shuo 
Signed-off-by: Zhao Yakui 
---
 drivers/staging/acrn/Makefile |   3 +-
 drivers/staging/acrn/acrn_dev.c   |  58 ++
 drivers/staging/acrn/acrn_drv_internal.h  |  33 ++
 drivers/staging/acrn/acrn_ioreq.c | 937 ++
 drivers/staging/acrn/acrn_vm_mngt.c   |   7 +
 include/linux/acrn/acrn_drv.h | 102 
 include/uapi/linux/acrn/acrn_common_def.h | 176 ++
 include/uapi/linux/acrn/acrn_ioctl_defs.h |  20 +
 8 files changed, 1335 insertions(+), 1 deletion(-)
 create mode 100644 drivers/staging/acrn/acrn_ioreq.c

diff --git a/drivers/staging/acrn/Makefile b/drivers/staging/acrn/Makefile
index ec62afe..a381944 100644
--- a/drivers/staging/acrn/Makefile
+++ b/drivers/staging/acrn/Makefile
@@ -3,4 +3,5 @@ acrn-y := acrn_dev.o \
  acrn_hypercall.o \
  acrn_vm_mngt.o \
  acrn_mm.o \
- acrn_mm_hugetlb.o
+ acrn_mm_hugetlb.o \
+ acrn_ioreq.o
diff --git a/drivers/staging/acrn/acrn_dev.c b/drivers/staging/acrn/acrn_dev.c
index 1476817..28258fb 100644
--- a/drivers/staging/acrn/acrn_dev.c
+++ b/drivers/staging/acrn/acrn_dev.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "acrn_hypercall.h"
 #include "acrn_drv_internal.h"
@@ -59,6 +60,9 @@ int acrn_dev_open(struct inode *inodep, struct file *filep)
INIT_HLIST_HEAD(>hugepage_hlist[i]);
mutex_init(>hugepage_lock);
 
+   INIT_LIST_HEAD(>ioreq_client_list);
+   spin_lock_init(>ioreq_client_lock);
+
write_lock_bh(_vm_list_lock);
vm_list_add(>list);
write_unlock_bh(_vm_list_lock);
@@ -131,9 +135,20 @@ long acrn_dev_ioctl(struct file *filep,
vm->vmid = created_vm->vmid;
atomic_set(>vcpu_num, 0);
 
+   ret = acrn_ioreq_init(vm, created_vm->req_buf);
+   if (ret < 0)
+   goto ioreq_buf_fail;
+
pr_info("acrn: VM %d created\n", created_vm->vmid);
kfree(created_vm);
break;
+
+ioreq_buf_fail:
+   hcall_destroy_vm(created_vm->vmid);
+   vm->vmid = ACRN_INVALID_VMID;
+   kfree(created_vm);
+   break;
+
}
 
case IC_START_VM: {
@@ -364,6 +379,47 @@ long acrn_dev_ioctl(struct file *filep,
break;
}
 
+   case IC_CREATE_IOREQ_CLIENT: {
+   int client_id;
+
+   client_id = acrn_ioreq_create_fallback_client(vm->vmid,
+ "acrndm");
+   if (client_id < 0)
+   return -EFAULT;
+   return client_id;
+   }
+
+   case IC_DESTROY_IOREQ_CLIENT: {
+   int client = ioctl_param;
+
+   acrn_ioreq_destroy_client(client);
+   break;
+   }
+
+   case IC_ATTACH_IOREQ_CLIENT: {
+   int client = ioctl_param;
+
+   return acrn_ioreq_attach_client(client);
+   }
+
+   case IC_NOTIFY_REQUEST_FINISH: {
+   struct ioreq_notify notify;
+
+   if (copy_from_user(, (void *)ioctl_param,
+  sizeof(notify)))
+   return -EFAULT;
+
+   ret = 

[RFC PATCH 02/15] x86/acrn: Add two APIs to add/remove driver-specific upcall ISR handler

2019-08-15 Thread Zhao Yakui
After the ACRN hypervisor sends the upcall notify interrupt, the upcall ISR
handler will be served. Now almost nothing is handled in upcall ISR handler
except acking EOI.
The driver-specific ISR handler is registered by the driver, which helps to
handle the real notification from ACRN hypervisor.
This is similar to that in XEN/HyperV.

Co-developed-by: Jason Chen CJ 
Signed-off-by: Jason Chen CJ 
Signed-off-by: Zhao Yakui 
---
 arch/x86/include/asm/acrn.h |  3 +++
 arch/x86/kernel/cpu/acrn.c  | 12 
 2 files changed, 15 insertions(+)

diff --git a/arch/x86/include/asm/acrn.h b/arch/x86/include/asm/acrn.h
index 4adb13f..857e6244 100644
--- a/arch/x86/include/asm/acrn.h
+++ b/arch/x86/include/asm/acrn.h
@@ -8,4 +8,7 @@ extern void acrn_hv_callback_vector(void);
 #endif
 
 extern void acrn_hv_vector_handler(struct pt_regs *regs);
+
+extern void acrn_setup_intr_irq(void (*handler)(void));
+extern void acrn_remove_intr_irq(void);
 #endif /* _ASM_X86_ACRN_H */
diff --git a/arch/x86/kernel/cpu/acrn.c b/arch/x86/kernel/cpu/acrn.c
index 95db5c4..a1ce52a 100644
--- a/arch/x86/kernel/cpu/acrn.c
+++ b/arch/x86/kernel/cpu/acrn.c
@@ -56,6 +56,18 @@ __visible void __irq_entry acrn_hv_vector_handler(struct 
pt_regs *regs)
set_irq_regs(old_regs);
 }
 
+void acrn_setup_intr_irq(void (*handler)(void))
+{
+   acrn_intr_handler = handler;
+}
+EXPORT_SYMBOL_GPL(acrn_setup_intr_irq);
+
+void acrn_remove_intr_irq(void)
+{
+   acrn_intr_handler = NULL;
+}
+EXPORT_SYMBOL_GPL(acrn_remove_intr_irq);
+
 const __initconst struct hypervisor_x86 x86_hyper_acrn = {
.name   = "ACRN",
.detect = acrn_detect,
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[RFC PATCH 00/15] acrn: add the ACRN driver module

2019-08-15 Thread Zhao Yakui
ACRN is a flexible, lightweight reference hypervisor, built with real-time
and safety-criticality in mind, optimized to streamline embedded development
through an open source platform. It is built for embedded IOT with small
footprint and real-time features. More details can be found
in https://projectacrn.org/

This is the patch set that add the ACRN driver module on ACRN guest, which
acts as the router to communciate with ACRN hypervisor.
The user-space applications can use the provided ACRN ioctls to
interact with ACRN hypervisor through different hypercalls. After the ACRN
module is loaded, the device file of /dev/acrn_hsm can be accessed in
user-space. It includes the management of virtualized CPU/memory/
device/interrupt/MMIO emulation for other ACRN guest. 
 
The first three patches are the changes under x86/acrn, which adds the
required APIs for the driver and reports the X2APIC caps. 
The remaining patches add the ACRN driver module, which accepts the ioctl
from user-space and then communicate with the low-level ACRN hypervisor
by using hypercall.


Zhao Yakui (15):
  x86/acrn: Report X2APIC for ACRN guest
  x86/acrn: Add two APIs to add/remove driver-specific upcall ISR handler
  x86/acrn: Add hypercall for ACRN guest
  drivers/acrn: add the basic framework of acrn char device driver
  drivers/acrn: add driver-specific hypercall for ACRN_HSM
  drivers/acrn: add the support of querying ACRN api version
  drivers/acrn: add acrn vm/vcpu management for ACRN_HSM char device
  drivers/acrn: add VM memory management for ACRN char device
  drivers/acrn: add passthrough device support
  drivers/acrn: add interrupt injection support
  drivers/acrn: add the support of handling emulated ioreq
  drivers/acrn: add driver-specific IRQ handle to dispatch IO_REQ request
  drivers/acrn: add service to obtain Power data transition
  drivers/acrn: add the support of irqfd and eventfd
  drivers/acrn: add the support of offline SOS cpu

 arch/x86/include/asm/acrn.h   |  57 ++
 arch/x86/kernel/cpu/acrn.c|  20 +-
 drivers/staging/Kconfig   |   2 +
 drivers/staging/Makefile  |   1 +
 drivers/staging/acrn/Kconfig  |  18 +
 drivers/staging/acrn/Makefile |   9 +
 drivers/staging/acrn/acrn_dev.c   | 727 +++
 drivers/staging/acrn/acrn_drv_internal.h  | 186 ++
 drivers/staging/acrn/acrn_hv_defs.h   |  65 +++
 drivers/staging/acrn/acrn_hypercall.c | 136 +
 drivers/staging/acrn/acrn_hypercall.h | 132 +
 drivers/staging/acrn/acrn_ioeventfd.c | 407 +
 drivers/staging/acrn/acrn_ioreq.c | 937 ++
 drivers/staging/acrn/acrn_irqfd.c | 339 +++
 drivers/staging/acrn/acrn_mm.c| 227 
 drivers/staging/acrn/acrn_mm_hugetlb.c| 281 +
 drivers/staging/acrn/acrn_vm_mngt.c   | 116 
 include/linux/acrn/acrn_drv.h | 200 +++
 include/uapi/linux/acrn/acrn_common_def.h | 201 +++
 include/uapi/linux/acrn/acrn_ioctl_defs.h | 345 +++
 20 files changed, 4400 insertions(+), 6 deletions(-)
 create mode 100644 drivers/staging/acrn/Kconfig
 create mode 100644 drivers/staging/acrn/Makefile
 create mode 100644 drivers/staging/acrn/acrn_dev.c
 create mode 100644 drivers/staging/acrn/acrn_drv_internal.h
 create mode 100644 drivers/staging/acrn/acrn_hv_defs.h
 create mode 100644 drivers/staging/acrn/acrn_hypercall.c
 create mode 100644 drivers/staging/acrn/acrn_hypercall.h
 create mode 100644 drivers/staging/acrn/acrn_ioeventfd.c
 create mode 100644 drivers/staging/acrn/acrn_ioreq.c
 create mode 100644 drivers/staging/acrn/acrn_irqfd.c
 create mode 100644 drivers/staging/acrn/acrn_mm.c
 create mode 100644 drivers/staging/acrn/acrn_mm_hugetlb.c
 create mode 100644 drivers/staging/acrn/acrn_vm_mngt.c
 create mode 100644 include/linux/acrn/acrn_drv.h
 create mode 100644 include/uapi/linux/acrn/acrn_common_def.h
 create mode 100644 include/uapi/linux/acrn/acrn_ioctl_defs.h

-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[RFC PATCH 05/15] drivers/acrn: add driver-specific hypercall for ACRN_HSM

2019-08-15 Thread Zhao Yakui
After the user-space calls the ioctls, the module will then call the
defined hypercall so that the ACRN hypervisor can take the corresponding
action. It includes the management of creating vcpu, guest memory
management and interrupt injection, pass-through device management.
The available driver-specific hypercalls for ACRN HSM module are added
so that the ACRN_HSM module can communicate with the low-level
ACRN hypervisor.

Co-developed-by: Jason Chen CJ 
Signed-off-by: Jason Chen CJ 
Co-developed-by: Jack Ren 
Signed-off-by: Jack Ren 
Co-developed-by: Yin FengWei 
Signed-off-by: Yin FengWei 
Co-developed-by: Liu Shuo 
Signed-off-by: Liu Shuo 
Signed-off-by: Zhao Yakui 
---
 drivers/staging/acrn/Makefile |   3 +-
 drivers/staging/acrn/acrn_hv_defs.h   |  65 
 drivers/staging/acrn/acrn_hypercall.c | 136 ++
 drivers/staging/acrn/acrn_hypercall.h | 132 +
 4 files changed, 335 insertions(+), 1 deletion(-)
 create mode 100644 drivers/staging/acrn/acrn_hv_defs.h
 create mode 100644 drivers/staging/acrn/acrn_hypercall.c
 create mode 100644 drivers/staging/acrn/acrn_hypercall.h

diff --git a/drivers/staging/acrn/Makefile b/drivers/staging/acrn/Makefile
index 48fca38..a58b0d1 100644
--- a/drivers/staging/acrn/Makefile
+++ b/drivers/staging/acrn/Makefile
@@ -1,2 +1,3 @@
 obj-$(CONFIG_ACRN_HSM) := acrn.o
-acrn-y := acrn_dev.o
+acrn-y := acrn_dev.o \
+ acrn_hypercall.o
diff --git a/drivers/staging/acrn/acrn_hv_defs.h 
b/drivers/staging/acrn/acrn_hv_defs.h
new file mode 100644
index 000..55417d2
--- /dev/null
+++ b/drivers/staging/acrn/acrn_hv_defs.h
@@ -0,0 +1,65 @@
+/* SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause */
+/*
+ * hypercall ID definition
+ *
+ */
+
+#ifndef _ACRN_HV_DEFS_H
+#define _ACRN_HV_DEFS_H
+
+/*
+ * Common structures for HV/HSM
+ */
+
+#define _HC_ID(x, y) (((x) << 24) | (y))
+
+#define HC_ID 0x80UL
+
+/* general */
+#define HC_ID_GEN_BASE   0x0UL
+#define HC_GET_API_VERSION  _HC_ID(HC_ID, HC_ID_GEN_BASE + 0x00)
+#define HC_SOS_OFFLINE_CPU  _HC_ID(HC_ID, HC_ID_GEN_BASE + 0x01)
+#define HC_GET_PLATFORM_INFO_HC_ID(HC_ID, HC_ID_GEN_BASE + 0x03)
+
+/* VM management */
+#define HC_ID_VM_BASE   0x10UL
+#define HC_CREATE_VM_HC_ID(HC_ID, HC_ID_VM_BASE + 0x00)
+#define HC_DESTROY_VM   _HC_ID(HC_ID, HC_ID_VM_BASE + 0x01)
+#define HC_START_VM _HC_ID(HC_ID, HC_ID_VM_BASE + 0x02)
+#define HC_PAUSE_VM _HC_ID(HC_ID, HC_ID_VM_BASE + 0x03)
+#define HC_CREATE_VCPU  _HC_ID(HC_ID, HC_ID_VM_BASE + 0x04)
+#define HC_RESET_VM _HC_ID(HC_ID, HC_ID_VM_BASE + 0x05)
+#define HC_SET_VCPU_REGS_HC_ID(HC_ID, HC_ID_VM_BASE + 0x06)
+
+/* IRQ and Interrupts */
+#define HC_ID_IRQ_BASE  0x20UL
+#define HC_INJECT_MSI   _HC_ID(HC_ID, HC_ID_IRQ_BASE + 0x03)
+#define HC_VM_INTR_MONITOR  _HC_ID(HC_ID, HC_ID_IRQ_BASE + 0x04)
+#define HC_SET_IRQLINE  _HC_ID(HC_ID, HC_ID_IRQ_BASE + 0x05)
+
+/* DM ioreq management */
+#define HC_ID_IOREQ_BASE0x30UL
+#define HC_SET_IOREQ_BUFFER _HC_ID(HC_ID, HC_ID_IOREQ_BASE + 0x00)
+#define HC_NOTIFY_REQUEST_FINISH_HC_ID(HC_ID, HC_ID_IOREQ_BASE + 0x01)
+
+/* Guest memory management */
+#define HC_ID_MEM_BASE  0x40UL
+#define HC_VM_SET_MEMORY_REGIONS_HC_ID(HC_ID, HC_ID_MEM_BASE + 0x02)
+#define HC_VM_WRITE_PROTECT_PAGE_HC_ID(HC_ID, HC_ID_MEM_BASE + 0x03)
+
+/* PCI assignment*/
+#define HC_ID_PCI_BASE  0x50UL
+#define HC_ASSIGN_PTDEV _HC_ID(HC_ID, HC_ID_PCI_BASE + 0x00)
+#define HC_DEASSIGN_PTDEV   _HC_ID(HC_ID, HC_ID_PCI_BASE + 0x01)
+#define HC_SET_PTDEV_INTR_INFO  _HC_ID(HC_ID, HC_ID_PCI_BASE + 0x03)
+#define HC_RESET_PTDEV_INTR_INFO_HC_ID(HC_ID, HC_ID_PCI_BASE + 0x04)
+
+/* DEBUG */
+#define HC_ID_DBG_BASE  0x60UL
+
+/* Power management */
+#define HC_ID_PM_BASE   0x80UL
+#define HC_PM_GET_CPU_STATE _HC_ID(HC_ID, HC_ID_PM_BASE + 0x00)
+#define HC_PM_SET_SSTATE_DATA   _HC_ID(HC_ID, HC_ID_PM_BASE + 0x01)
+
+#endif /* __ACRN_HV_DEFS_H */
diff --git a/drivers/staging/acrn/acrn_hypercall.c 
b/drivers/staging/acrn/acrn_hypercall.c
new file mode 100644
index 000..6d83475
--- /dev/null
+++ b/drivers/staging/acrn/acrn_hypercall.c
@@ -0,0 +1,136 @@
+// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
+/*
+ * ACRN hyperviosr service module (HSM): driver-specific hypercall
+ *
+ * Copyright (C) 2019 Intel Corporation. All rights reserved.
+ * Jason Chen CJ 
+ * Zhao Yakui 
+ * Jack Ren 
+ * Yin FengWei 
+ * Liu Shuo 
+ */
+
+#include 
+#include 
+#include 
+#include "acrn_hv_defs.h"
+#include "acrn_hypercall.h"
+
+/* General */
+long hcall_get_api_version(unsigned long api_version)
+{
+   return acrn_hypercall1(HC_GET_API_VERSION, api_version);
+}
+
+long hcall_sos_offline_cpu(unsigned long cpu)
+{
+   

[RFC PATCH 07/15] drivers/acrn: add acrn vm/vcpu management for ACRN_HSM char device

2019-08-15 Thread Zhao Yakui
The VM management is one important role of acrn module. It is used to
manage another VM based on the user-space ioctls. It includes the
following VM operation: CREATE/START/PAUSE/DESTROY VM, CREATE_VCPU,
IC_SET_VCPU_REGS.
acrn_ioctl is provided so that the user of /dev/acrn_hsm can manage
the VM for the given guest. After the ioctl is called, the hypercall
is then called so that the ACRN hypervisor can help to manage the
corresponding VM and create the required VCPU.

As ACRN is mainly used for embedded IOT usage, no interface is provided
to destroy the vcpu explicitly. When the VM is destroyed, the low-level
ACRN hypervisor will free the corresponding vcpu implicitly.

Co-developed-by: Jason Chen CJ 
Signed-off-by: Jason Chen CJ 
Co-developed-by: Liu Shuo 
Signed-off-by: Liu Shuo 
Signed-off-by: Zhao Yakui 
---
 drivers/staging/acrn/Makefile |   3 +-
 drivers/staging/acrn/acrn_dev.c   | 169 +-
 drivers/staging/acrn/acrn_drv_internal.h  |  74 +
 drivers/staging/acrn/acrn_vm_mngt.c   |  72 +
 include/uapi/linux/acrn/acrn_ioctl_defs.h | 126 ++
 5 files changed, 442 insertions(+), 2 deletions(-)
 create mode 100644 drivers/staging/acrn/acrn_drv_internal.h
 create mode 100644 drivers/staging/acrn/acrn_vm_mngt.c

diff --git a/drivers/staging/acrn/Makefile b/drivers/staging/acrn/Makefile
index a58b0d1..426d6e8 100644
--- a/drivers/staging/acrn/Makefile
+++ b/drivers/staging/acrn/Makefile
@@ -1,3 +1,4 @@
 obj-$(CONFIG_ACRN_HSM) := acrn.o
 acrn-y := acrn_dev.o \
- acrn_hypercall.o
+ acrn_hypercall.o \
+ acrn_vm_mngt.o
diff --git a/drivers/staging/acrn/acrn_dev.c b/drivers/staging/acrn/acrn_dev.c
index 57cd2bb..7372316 100644
--- a/drivers/staging/acrn/acrn_dev.c
+++ b/drivers/staging/acrn/acrn_dev.c
@@ -27,6 +27,7 @@
 #include 
 
 #include "acrn_hypercall.h"
+#include "acrn_drv_internal.h"
 
 #define  DEVICE_NAME "acrn_hsm"
 #define  CLASS_NAME  "acrn"
@@ -42,8 +43,22 @@ static struct device *acrn_device;
 static
 int acrn_dev_open(struct inode *inodep, struct file *filep)
 {
-   pr_info("%s: opening device node\n", __func__);
+   struct acrn_vm *vm;
+
+   vm = kzalloc(sizeof(*vm), GFP_KERNEL);
+   if (!vm)
+   return -ENOMEM;
+
+   refcount_set(>refcnt, 1);
+   vm->vmid = ACRN_INVALID_VMID;
+   vm->dev = acrn_device;
 
+   write_lock_bh(_vm_list_lock);
+   vm_list_add(>list);
+   write_unlock_bh(_vm_list_lock);
+   filep->private_data = vm;
+
+   pr_info("%s: opening device node\n", __func__);
return 0;
 }
 
@@ -52,6 +67,15 @@ long acrn_dev_ioctl(struct file *filep,
unsigned int ioctl_num, unsigned long ioctl_param)
 {
long ret = 0;
+   struct acrn_vm *vm;
+
+   pr_debug("[%s] ioctl_num=0x%x\n", __func__, ioctl_num);
+
+   vm = (struct acrn_vm *)filep->private_data;
+   if (!vm) {
+   pr_err("acrn: invalid VM !\n");
+   return -EFAULT;
+   }
 
if (ioctl_num == IC_GET_API_VERSION) {
struct api_version api_version;
@@ -66,11 +90,154 @@ long acrn_dev_ioctl(struct file *filep,
return 0;
}
 
+   if ((vm->vmid == ACRN_INVALID_VMID) && (ioctl_num != IC_CREATE_VM)) {
+   pr_err("acrn: invalid VM ID for IOCTL %x!\n", ioctl_num);
+   return -EFAULT;
+   }
+
+   switch (ioctl_num) {
+   case IC_CREATE_VM: {
+   struct acrn_create_vm *created_vm;
+
+   created_vm = kmalloc(sizeof(*created_vm), GFP_KERNEL);
+   if (!created_vm)
+   return -ENOMEM;
+
+   if (copy_from_user(created_vm, (void *)ioctl_param,
+  sizeof(struct acrn_create_vm))) {
+   kfree(created_vm);
+   return -EFAULT;
+   }
+
+   ret = hcall_create_vm(virt_to_phys(created_vm));
+   if ((ret < 0) || (created_vm->vmid == ACRN_INVALID_VMID)) {
+   pr_err("acrn: failed to create VM from Hypervisor !\n");
+   kfree(created_vm);
+   return -EFAULT;
+   }
+
+   if (copy_to_user((void *)ioctl_param, created_vm,
+sizeof(struct acrn_create_vm))) {
+   kfree(created_vm);
+   return -EFAULT;
+   }
+
+   vm->vmid = created_vm->vmid;
+   atomic_set(>vcpu_num, 0);
+
+   pr_info("acrn: VM %d created\n", created_vm->vmid);
+   kfree(created_vm);
+   break;
+   }
+
+   case IC_START_VM: {
+   ret = hcall_start_vm(vm->vmid);
+   if (ret < 0) {
+   pr_err("acrn: failed to start VM %d!\n", vm->vmid);
+   return -EFAULT;
+   }
+   break;
+   }
+

[RFC PATCH 01/15] x86/acrn: Report X2APIC for ACRN guest

2019-08-15 Thread Zhao Yakui
After lapic is switched from xapic to x2apic mode, it can use the APIC
MSR register to access local apic register in ACRN guest. This will
help to remove some traps of lapic access in ACRN guest.
Report the X2APIC so that the ACRN guest can be switched to x2apic mode.

Co-developed-by: Jason Chen CJ 
Signed-off-by: Jason Chen CJ 
Signed-off-by: Zhao Yakui 
---
 arch/x86/kernel/cpu/acrn.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/cpu/acrn.c b/arch/x86/kernel/cpu/acrn.c
index 676022e..95db5c4 100644
--- a/arch/x86/kernel/cpu/acrn.c
+++ b/arch/x86/kernel/cpu/acrn.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -29,12 +30,7 @@ static void __init acrn_init_platform(void)
 
 static bool acrn_x2apic_available(void)
 {
-   /*
-* x2apic is not supported for now. Future enablement will have to check
-* X86_FEATURE_X2APIC to determine whether x2apic is supported in the
-* guest.
-*/
-   return false;
+   return boot_cpu_has(X86_FEATURE_X2APIC);
 }
 
 static void (*acrn_intr_handler)(void);
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[RFC PATCH 06/15] drivers/acrn: add the support of querying ACRN api version

2019-08-15 Thread Zhao Yakui
In order to assure that the ACRN module can work with the required ACRN
hypervisor, it needs to check whether the required version is consistent
with the queried version from ACRN ypervisor. If it is inconsistent, it
won't coninue the initialization of ACRN_HSM module.
Similarly the user-space module also needs to check the driver version.

Co-developed-by: Jason Chen CJ 
Signed-off-by: Jason Chen CJ 
Co-developed-by: Liu Shuo 
Signed-off-by: Liu Shuo 
Signed-off-by: Zhao Yakui 
---
 drivers/staging/acrn/acrn_dev.c   | 47 +++
 include/uapi/linux/acrn/acrn_ioctl_defs.h | 32 +
 2 files changed, 79 insertions(+)
 create mode 100644 include/uapi/linux/acrn/acrn_ioctl_defs.h

diff --git a/drivers/staging/acrn/acrn_dev.c b/drivers/staging/acrn/acrn_dev.c
index 55a7612..57cd2bb 100644
--- a/drivers/staging/acrn/acrn_dev.c
+++ b/drivers/staging/acrn/acrn_dev.c
@@ -18,13 +18,22 @@
 #include 
 #include 
 #include 
+#include 
 #include 
+#include 
+#include 
 #include 
 #include 
+#include 
+
+#include "acrn_hypercall.h"
 
 #define  DEVICE_NAME "acrn_hsm"
 #define  CLASS_NAME  "acrn"
 
+#define ACRN_API_VERSION_MAJOR 1
+#define ACRN_API_VERSION_MINOR 0
+
 static int acrn_hsm_inited;
 static int major;
 static struct class*acrn_class;
@@ -44,6 +53,19 @@ long acrn_dev_ioctl(struct file *filep,
 {
long ret = 0;
 
+   if (ioctl_num == IC_GET_API_VERSION) {
+   struct api_version api_version;
+
+   api_version.major_version = ACRN_API_VERSION_MAJOR;
+   api_version.minor_version = ACRN_API_VERSION_MINOR;
+
+   if (copy_to_user((void *)ioctl_param, _version,
+sizeof(api_version)))
+   return -EFAULT;
+
+   return 0;
+   }
+
return ret;
 }
 
@@ -59,9 +81,12 @@ static const struct file_operations fops = {
 };
 
 #define EAX_PRIVILEGE_VM   BIT(0)
+#define SUPPORT_HV_API_VERSION_MAJOR   1
+#define SUPPORT_HV_API_VERSION_MINOR   0
 
 static int __init acrn_init(void)
 {
+   struct api_version *api_version;
acrn_hsm_inited = 0;
if (x86_hyper_type != X86_HYPER_ACRN)
return -ENODEV;
@@ -69,6 +94,28 @@ static int __init acrn_init(void)
if (!(cpuid_eax(0x4001) & EAX_PRIVILEGE_VM))
return -EPERM;
 
+   api_version = kmalloc(sizeof(*api_version), GFP_KERNEL);
+   if (!api_version)
+   return -ENOMEM;
+
+   if (hcall_get_api_version(virt_to_phys(api_version)) < 0) {
+   pr_err("acrn: failed to get api version from Hypervisor !\n");
+   kfree(api_version);
+   return -EINVAL;
+   }
+
+   if (api_version->major_version >= SUPPORT_HV_API_VERSION_MAJOR &&
+   api_version->minor_version >= SUPPORT_HV_API_VERSION_MINOR) {
+   pr_info("acrn: hv api version %d.%d\n",
+   api_version->major_version, api_version->minor_version);
+   kfree(api_version);
+   } else {
+   pr_err("acrn: not support hv api version %d.%d!\n",
+  api_version->major_version, api_version->minor_version);
+   kfree(api_version);
+   return -EINVAL;
+   }
+
/* Try to dynamically allocate a major number for the device */
major = register_chrdev(0, DEVICE_NAME, );
if (major < 0) {
diff --git a/include/uapi/linux/acrn/acrn_ioctl_defs.h 
b/include/uapi/linux/acrn/acrn_ioctl_defs.h
new file mode 100644
index 000..8dbf69a
--- /dev/null
+++ b/include/uapi/linux/acrn/acrn_ioctl_defs.h
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause */
+/**
+ * @file acrn_ioctl_defs.h
+ *
+ * ACRN definition for ioctl to user space
+ */
+
+#ifndef __ACRN_IOCTL_DEFS_H__
+#define __ACRN_IOCTL_DEFS_H__
+
+/**
+ * struct api_version - data structure to track ACRN_SRV API version
+ *
+ * @major_version: major version of ACRN_SRV API
+ * @minor_version: minor version of ACRN_SRV API
+ */
+struct api_version {
+   uint32_t major_version;
+   uint32_t minor_version;
+};
+
+/*
+ * Common IOCTL ID definition for DM
+ */
+#define _IC_ID(x, y) (((x) << 24) | (y))
+#define IC_ID 0x43UL
+
+/* General */
+#define IC_ID_GEN_BASE  0x0UL
+#define IC_GET_API_VERSION _IC_ID(IC_ID, IC_ID_GEN_BASE + 0x00)
+
+#endif /* __ACRN_IOCTL_DEFS_H__ */
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[RFC PATCH 03/15] x86/acrn: Add hypercall for ACRN guest

2019-08-15 Thread Zhao Yakui
When ACRN hypervisor is detected, the hypercall is needed so that the
ACRN guest can query/config some settings. For example: it can be used
to query the resources in hypervisor and manage the CPU/memory/device/
interrupt for guest operating system.

On x86 it is implemented with the VMCALL instruction.

Co-developed-by: Jason Chen CJ 
Signed-off-by: Jason Chen CJ 
Signed-off-by: Zhao Yakui 
---
 arch/x86/include/asm/acrn.h | 54 +
 1 file changed, 54 insertions(+)

diff --git a/arch/x86/include/asm/acrn.h b/arch/x86/include/asm/acrn.h
index 857e6244..ab97c3d 100644
--- a/arch/x86/include/asm/acrn.h
+++ b/arch/x86/include/asm/acrn.h
@@ -11,4 +11,58 @@ extern void acrn_hv_vector_handler(struct pt_regs *regs);
 
 extern void acrn_setup_intr_irq(void (*handler)(void));
 extern void acrn_remove_intr_irq(void);
+
+/*
+ * Hypercalls for ACRN guest
+ *
+ * Hypercall number is passed in R8 register.
+ * Up to 2 arguments are passed in RDI, RSI.
+ * Return value will be placed in RAX.
+ */
+static inline long acrn_hypercall0(unsigned long hcall_id)
+{
+   long result;
+
+   /* the hypercall is implemented with the VMCALL instruction.
+* volatile qualifier is added to avoid that it is dropped
+* because of compiler optimization.
+*/
+   asm volatile("movq %[hcall_id], %%r8\n\t"
+"vmcall\n\t"
+: "=a" (result)
+: [hcall_id] "g" (hcall_id)
+: "r8");
+
+   return result;
+}
+
+static inline long acrn_hypercall1(unsigned long hcall_id,
+  unsigned long param1)
+{
+   long result;
+
+   asm volatile("movq %[hcall_id], %%r8\n\t"
+"vmcall\n\t"
+: "=a" (result)
+: [hcall_id] "g" (hcall_id), "D" (param1)
+: "r8");
+
+   return result;
+}
+
+static inline long acrn_hypercall2(unsigned long hcall_id,
+  unsigned long param1,
+  unsigned long param2)
+{
+   long result;
+
+   asm volatile("movq %[hcall_id], %%r8\n\t"
+"vmcall\n\t"
+: "=a" (result)
+: [hcall_id] "g" (hcall_id), "D" (param1), "S" (param2)
+: "r8");
+
+   return result;
+}
+
 #endif /* _ASM_X86_ACRN_H */
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel