Re: How to properly write tests for kernel functions

2015-11-04 Thread Greg KH
On Thu, Nov 05, 2015 at 12:26:01AM +0300, Maxim Pugachev wrote:
> Hi all,
> 
> I'm trying to understand is there any uniform way to write tests? For
> example, lib/ folder has a bunch of tests, but all of them use various
> technics:
> 
> - pr_warn/pr_err (i.e. printk) or WARN for assertions
> - just tens of functions that check something, or unified macros
> - no naming convention for test cases
> 
> So, I'm wondering, whether there is an example or guidelines that is
> worth to follow.

It all depends on what you want to test.  There is no "general" way to
do this as all subsystems / parts of the kernel are different.

thanks,

greg k-h

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


How to properly write tests for kernel functions

2015-11-04 Thread Maxim Pugachev
Hi all,

I'm trying to understand is there any uniform way to write tests? For
example, lib/ folder has a bunch of tests, but all of them use various
technics:

- pr_warn/pr_err (i.e. printk) or WARN for assertions
- just tens of functions that check something, or unified macros
- no naming convention for test cases

So, I'm wondering, whether there is an example or guidelines that is
worth to follow.

Thanks!

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: [PATCH v3 0/4] SysFS driver for QEMU fw_cfg device

2015-11-04 Thread Gabriel L. Somlo
On Mon, Oct 05, 2015 at 03:18:05PM +0200, Paolo Bonzini wrote:
> 
> 
> On 05/10/2015 14:50, Peter Maydell wrote:
> > If you want to try to support "firmware might also be reading
> > fw_cfg at the same time as the kernel" this is a (painful)
> > problem regardless of how the kernel figures out whether a
> > fw_cfg device is present. I had assumed that one of the design
> > assumptions of this series was that firmware would only
> > read the fw_cfg before booting the guest kernel and never touch
> > it afterwards. If it might touch it later then letting the
> > guest kernel also mess with fw_cfg seems like a really bad idea.
> 
> The idea of tinkering with fw_cfg from the AML code (DSDT/SSDT) has been
> proposed many times, and always dropped.  One of the reasons was that
> the OS could have a driver for fw_cfg.
> 
> So I think that we can define the QEMU0002 id as owned by the OSPM,
> similar to the various standard ACPI ids that are usually found in the
> x86 world (e.g. PNP0B00 is a mc146818 RTC, PNP0303 is an 8042 keyboard
> controller, PNP0501 is a 16550 or similar UART, and so on).  This
> basically sanctions _CRS as the way to pass information from the
> firmware to the OSPM, also similarly to those standard PNP ids.

OK, so I don't expect to go the "pure ACPI" route in the final
version, mainly because I'm still hoping to fill the requirement
of writing a driver which can use either ACPI or DT to detect the
presence of fw_cfg (how I'm going to compile this on kernels with
no ACPI or no DT support is still TBD, and probably will have to
involve #ifdef, but I digress :)

However, Michael's idea of having ACPI supply an "accessor method" for
the guest kernel driver to call, without having to worry about the
specific details in _CRS, sounded intriguing enough to at least explore
in further detail.

So, assuming we have the following fw_cfg AML in ssdt (i386) or
dsdt (arm) (using cpp-style #ifdef to highlight the arch-specific
bits):

Scope (\_SB)
{
Device (FWCF)
{
Name (_HID, EisaId ("QMU0002"))  // _HID: Hardware ID
Name (_STA, 0x0B)  // _STA: Status

#ifdef ARCH_X86

Name (_CRS, ResourceTemplate ()
{
IO (Decode16,
0x0510, // Range Minimum
0x0510, // Range Maximum
0x01,   // Alignment
0x02,   // Length
)
})

#else /* ARCH_ARM */

NAME (_CRS, ResourceTemplate ()
{
Memory32Fixed (ReadWrite,
   0x0902,  // Address Base
   0x000a,  // Address Length
  )
})

#endif

}
}

I can easily patch QEMU to additionally insert the following into
"Device (FWCF)":

#ifdef ARCH_X86

OperationRegion (FWCR, SystemIO, 0x0510, 0x02)
Field (FWCR, WordAcc, NoLock, Preserve)
{
FWCC,   16
}
Field (FWCR, ByteAcc, NoLock, Preserve)
{
Offset (0x01),
FWCD,   8
}

#else /* ARCH_ARM */

OperationRegion (FWCR, SystemMemory, 0x0902, 0x0a)
Field (FWCR, WordAcc, NoLock, Preserve)
{
Offset (0x08),
FWCC,   16  // not sure about endianness on ARM here, but
// I can still address this from the userspace
// kernel driver if needed
}
Field (FWCR, ByteAcc, NoLock, Preserve)
{
FWCD,   8
}

#endif

Method (RDBL, 3, Serialized) // (Arg0 = key, Arg1 = skip, Arg2 = count)
{
FWCC = Arg0
Local0 = Zero
While ((Local0 < Arg1))
{
Local1 = FWCD
Local0++
}
Name (BBUF, Buffer (Arg2) {})
Local0 = Zero
While ((Local0 < Arg2))
{
Index (BBUF, Local0) = FWCD /* \_SB_.FWCF.FWCD */
Local0++
}
Return (BBUF) /* \_SB_.FWCF.RDBL.BBUF */
}

With the host generating the additional RDBL method above, I could
write a "pure ACPI" driver for the guest kernel, where instead of the
current fw_cfg_read_blob() logic:


  static DEFINE_MUTEX(fw_cfg_dev_lock);
  static bool fw_cfg_is_mmio;

  static inline u16 fw_cfg_sel_endianness(u16 key)
  {
  return fw_cfg_is_mmio ? cpu_to_be16(key) : cpu_to_le16(key);
  }

  static inline void fw_cfg_read_blob(u16 key,
  void *buf, loff_t pos, size_t count)
  {
  mutex_lock(&fw_cfg_dev_lock);
  iowrite16(fw_cfg_sel_endianness(key), fw_cfg_reg_ctrl);
  while (pos-- > 0)
  ioread8(fw_cfg_reg_data);
  ioread8_rep(fw_cfg_reg_data, buf, count);
  mutex_unlock(&fw_cfg_dev_lock);
  }


I could instead write something like this:


  struct acpi_device *dev;/* set during module init.  */

  static i

Bluetooth doesn't work

2015-11-04 Thread Kinka Huang
Hi all,
Thinkpad X1 2015, ubuntu 15.10, the bluetooth module seems not work well.
Once connect, it prints the following kernel log:

[  196.730943] Bluetooth: hci0 SCO packet for unknown connection handle 0
[  196.730946] Bluetooth: hci0 SCO packet for unknown connection handle 0
[  196.730948] Bluetooth: hci0 SCO packet for unknown connection handle 0
[  196.740970] Bluetooth: hci0 SCO packet for unknown connection handle 0
[  196.740975] Bluetooth: hci0 SCO packet for unknown connection handle 0
[  196.740976] Bluetooth: hci0 SCO packet for unknown connection handle 0
[  201.764755] Bluetooth: hci0 SCO packet for unknown connection handle 257
[  201.764768] Bluetooth: hci0 SCO packet for unknown connection handle 257
[  201.764777] Bluetooth: hci0 SCO packet for unknown connection handle 257

and something I think related while kernel initing:

[3.738275] usbcore: registered new interface driver btusb
[3.754215] Bluetooth: hci0: read Intel version: 370810011003110e00
[3.755429] Adding 796k swap on /swap/swapfile.  Priority:-1
extents:66 across:13275644k SSFS
[3.757145] Bluetooth: hci0: Intel Bluetooth firmware file:
intel/ibt-hw-37.8.10-fw-1.10.3.11.e.bseq

I think it is a good chance for me to diving into the linux kernel, so
can anyone offer some hints that I could solve this problem.

$ uname -ar
Linux kinka-X1 4.3.0-rc7+ #50 SMP Wed Oct 28 22:49:01 CST 2015 x86_64
x86_64 x86_64 GNU/Linux

Many thanks~

Kinka

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies