Skip to contentSkip to conversation

3.16.57-rc1 review

PATCH In review Ben Hutchings 7 participants 428 messages Jun 7, 2018 – Nov 12, 2018 2 messages not in the archive Page 1 of 3

Subsystems (16)
Stable branch x86 KVM Kernel janitors +12 more subsystems
lore
Share & tools
lore
#0 lore raw

cover 3.16.57-rc1 review

This is the start of the stable review cycle for the 3.16.57 release. There are 410 patches in this series, which will be posted as responses to this one. If anyone has any issues with these being applied, please let me know.

Responses should be made by Thu Jun 14 18:00:00 UTC 2018. Anything received after that time might be too late.

All the patches have also been committed to the linux-3.16.y-rc branch of
https://git.kernel.org/pub/scm/linux/kernel/git/bwh/linux-stable-rc.git . A shortlog and diffstat can be found below.

Ben.

-------------

Adrian Hunter (2):
mmc: sdhci-pci: Fix S0i3 for Intel BYT-based controllers
[f8870ae6e2d6be75b1accc2db981169fdfbea7ab]
mmc: sdhci: Allow override of mmc host operations
[bf60e592a1af4d6f65dd54593250183f14360eed]

Al Viro (2):
Bluetooth: hidp_connection_add() unsafe use of l2cap_pi()
[51bda2bca53b265715ca1852528f38dc67429d9a]
lock_parent() needs to recheck if dentry got __dentry_kill'ed under it
[3b821409632ab778d46e807516b457dfa72736ed]

Alaa Hleihel (1):
IB/ipoib: Do not warn if IPoIB debugfs doesn't exist
[14fa91e0fef8e4d6feb8b1fa2a807828e0abe815]

Alex Chen (1):

      ocfs2: subsystem.su_mutex is required while accessing the  item->ci_parent
         [853bc26a7ea39e354b9f8889ae7ad1492ffa28d2]

Alex Deucher (2):
drm/radeon: Add dpm quirk for Jet PRO (v2)
[239b5f64e12b1f09f506c164dff0374924782979]
drm/radeon: fix KV harvesting
[0b58d90f89545e021d188c289fa142e5ff9e708b]

Alexander Graf (1):
KVM: PPC: Book3S PR: Fix svcpu copying with preemption enabled
[07ae5389e98c53bb9e9f308fce9c903bc3ee7720]

Alexander Potapenko (1):
netlink: make sure nladdr has correct size in netlink_connect()
[7880287981b60a6808f39f297bb66936e8bdf57a]

Alexandra Yates (3):
Adding Intel Lewisburg device IDs for SATA
[f5bdd66c705484b4bc77eb914be15c1b7881fae7]
ahci: Order SATA device IDs for codename Lewisburg
[4d92f0099a06ef0e36c7673f7c090f1a448b2d1b]
ahci: add new Intel device IDs
[56e74338a535cbcc2f2da08b1ea1a92920194364]

Alexandru Ardelean (1):
staging: iio: adc: ad7192: fix external frequency setting
[e31b617d0a63c6558485aaa730fd162faa95a766]

Alexey Kodanev (4):
dccp: check sk for closed state in dccp_sendmsg()
[67f93df79aeefc3add4e4b31a752600f834236e2]
sch_netem: fix skb leak in netem_enqueue()
[35d889d10b649fda66121891ec05eca88150059d]
sctp: verify size of a new chunk in _sctp_make_chunk()
[07f2c7ab6f8d0a7e7c5764c4e6cc9c52951b9d9c]
udplite: fix partial checksum initialization
[15f35d49c93f4fa9875235e7bf3e3783d2dd7a1b]

Aman Deep (1):
usb: ohci: Proper handling of ed_rm_list to handle race condition between usb_kill_urb() and finish_unlinks()
[46408ea558df13b110e0866b99624384a33bdeba]

Anand Jain (1):
btrfs: use proper endianness accessors for super_copy
[3c181c12c431fe33b669410d663beb9cceefcd1b]

Andi Shyti (1):
Input: mms114 - fix license module information
[498e7e7ed1fd72c275a682f0903c4a20cc538658]

Andrew F. Davis (1):
ARM: dts: omap3-n900: Fix the audio CODEC's reset pin
[7be4b5dc7ffa9499ac6ef33a5ffa9ff43f9b7057]

Andri Yngvason (3):
can: cc770: Fix queue stall & dropped RTR reply
[746201235b3f876792099079f4c6fea941d76183]
can: cc770: Fix stalls on rt-linux, remove redundant IRQ ack
[f4353daf4905c0099fd25fa742e2ffd4a4bab26a]
can: cc770: Fix use after free in cc770_tx_interrupt()
[9ffd7503944ec7c0ef41c3245d1306c221aef2be]

Andy Lutomirski (1):
x86/entry/64: Don't use IST entry for #BP stack
[d8ba61ba58c88d5207c1ba2f7d9a2280e7d03be9]

Andy Shevchenko (1):
x86/cpu: Rename Merrifield2 to Moorefield
[f5fbf848303c8704d0e1a1e7cabd08fd0a49552f]

Anna-Maria Gleixner (1):
hrtimer: Ensure POSIX compliance (relative CLOCK_REALTIME hrtimers)
[48d0c9becc7f3c66874c100c126459a9da0fdced]

Arend Van Spriel (1):
brcmfmac: fix P2P_DEVICE ethernet address generation
[455f3e76cfc0d893585a5f358b9ddbe9c1e1e53b]

Arkadi Sharshevsky (1):
team: Fix double free in error path
[cbcc607e18422555db569b593608aec26111cb0b]

Arnaldo Carvalho de Melo (3):

      perf evlist: Introduce perf_evlist__new_dummy constructor
         [5bae0250237f7a5ec4355f9920701de247b8db91]
      perf record: Generate PERF_RECORD_{MMAP,COMM,EXEC} with --delay
         [d3dbf43c56f9176be325ce1cc72a44c8d3c210dc]
      perf report: Fix -D output for user metadata events
         [f250b09c779550e4a7a412dae6d3ad34d5201019]

Arnd Bergmann (7):

      cfg80211: fix cfg80211_beacon_dup
         [bee92d06157fc39d5d7836a061c7d41289a55797]
      cifs: silence compiler warnings showing up with gcc-8.0.0
         [ade7db991b47ab3016a414468164f4966bd08202]
      media: exynos4-is: properly initialize frame format
         [97913bcbe6da3957af27d9fdd76b3d97b99e6d6a]
      mm: hide a #warning for COMPILE_TEST
         [af27d9403f5b80685b79c88425086edccecaf711]
      scsi: fas216: fix sense buffer initialization
         [96d5eaa9bb74d299508d811d865c2c41b38b0301]
      x86/oprofile: Fix bogus GCC-8 warning in nmi_setup()
         [85c615eb52222bc5fab6c7190d146bc59fac289e]
      x86/pti: Mark constant arrays as __initconst
         [4bf5d56d429cbc96c23d809a08f63cd29e1a702e]

Ashok Raj (1):
KVM/x86: Add IBPB support
[15d45071523d89b3fb7372e2135fbd72f6af9506]

Aurelien Aptel (1):
CIFS: zero sensitive data when freeing
[97f4b7276b829a8927ac903a119bef2f963ccc58]

Baolin Wang (1):
usb: gadget: f_fs: Fix possibe deadlock
[b3ce3ce02d146841af012d08506b4071db8ffde3]

Bart Van Assche (1):
pktcdvd: Fix pkt_setup_dev() error path
[5a0ec388ef0f6e33841aeb810d7fa23f049ec4cd]

Bastian Stender (1):
mmc: block: fix updating ext_csd caches on ioctl call
[e74ef2194b41ba5e511fab29fe5ff00e72d2f42a]

Ben Crocker (1):
drm/radeon: insist on 32-bit DMA for Cedar on PPC64/PPC64LE
[2c83029cda55a5e7665c7c6326909427d6a01350]

Ben Hutchings (3):
skb: Add skb_postpush_rcsum()
[f8ffad69c9f8b8dfb0b633425d4ef4d2493ba61a]
staging: android: ashmem: Fix a race condition in pin ioctls
[ce8a3a9e76d0193e2e8d74a06d275b3c324ca652]
xen: Add xen_arch_suspend()
[2b953a5e994ce279904ec70220f7d4f31d380a0a]

Benjamin Poirier (1):
e1000e: Fix check_for_link return value with autoneg off
[4e7dc08e57c95673d2edaba8983c3de4dd1f65f5]

Bjorn Andersson (1):
PM / devfreq: Propagate error from devfreq_add_device()
[d1bf2d30728f310f72296b54f0651ecdb09cbb12]

Boris Ostrovsky (1):
xen/arm: Define xen_arch_suspend()
[ffb7dbed47da6ac4460b606a3feee295bbe4d9e2]

Boris Pismenny (1):
IB/mlx5: Fix integer overflows in mlx5_ib_create_srq
[c2b37f76485f073f020e60b5954b6dc4e55f693c]

Borislav Petkov (2):
x86, microcode: Fix accessing dis_ucode_ldr on 32-bit
[85be07c32496dc264661308e4d9d4e9ccaff8072]
x86/microcode/AMD: Do not load when running on a hypervisor
[a15a753539eca8ba243d576f02e7ca9c4b7d7042]

[email protected] (1):
ahci: Add Device ID for Intel Sunrise Point PCH
[c5967b79ecabe2baca40658d9073e28b30d7f6cf]

Chenjie (1):
mm/madvise.c: fix madvise() infinite loop under special circumstances
[6ea8d958a2c95a1d514015d4e29ba21a8c0a1a91]

Chien Tin Tung (1):
RDMA/ucma: Correct option size check using optlen
[5f3e3b85cc0a5eae1c46d72e47d3de7bf208d9e2]

Christian Borntraeger (1):
KVM: s390: provide io interrupt kvm_stat
[09a0fb67536a49af19f2bfc632100e9de91fe526]

Christian König (2):
drm/radeon: fix prime teardown order
[0f4f715bc6bed3bf14c5cd7d5fe88d443e756b14]
drm/ttm: fix adding foreign BOs to the swap LRU
[ed704a43e84cc536081423dcd3491acf2791aaeb]

Christophe JAILLET (3):

      media: bt8xx: Fix err 'bt878_probe()'
         [45392ff6881dbe56d41ef0b17c2e576065f8ffa1]
      power: supply: ab8500_charger: Bail out in case of error in 'ab8500_charger_init_hw_registers()'
         [09edcb647542487864e23aa8d2ef26be3e08978a]
      power: supply: ab8500_charger: Fix an error handling path
         [bf59fddde1c3eab89eb8dca8f3d3dc097887d2bb]

Clay McClure (1):
ubi: Fix race condition between ubi volume creation and udev
[a51a0c8d213594bc094cb8e54aad0cb6d7f7b9a6]

Colin Ian King (3):
clocksource/drivers/fsl_ftm_timer: Fix error return checking
[f287eb9013ccf199cbfa4eabd80c36fedfc15a73]
scsi: aacraid: remove redundant setting of variable c
[91814744646351a470f256fbcb853fb5a7229a9f]
wl1251: check return from call to wl1251_acx_arp_ip_filter
[ac1181c60822292176ab96912208ec9f9819faf8]

Cong Wang (2):
netfilter: ipt_CLUSTERIP: fix a refcount bug in clusterip_config_find_get()
[db93a3632b0f8773a3899e04a3a3e0aa7a26eb46]
netfilter: xt_RATEEST: acquire xt_rateest_mutex for hash insert
[7dc68e98757a8eccf8ca7a53a29b896f1eef1f76]

Corentin Labbe (2):
ia64: convert unwcheck.py to python3
[bd5edbe677948d0883f59d9625c444818d5284b1]
powerpc/pseries: Add empty update_numa_cpu_lookup_table() for NUMA=n
[c1e150ceb61e4a585bad156da15c33bfe89f5858]

Dan Aloni (1):
cifs: empty TargetInfo leads to crash on recovery
[cabfb3680f78981d26c078a26e5c748531257ebb]

Dan Carpenter (10):
ALSA: pcm: potential uninitialized return values
[5607dddbfca774fb38bffadcb077fe03aa4ac5c6]
ASoC: au1x: Fix timeout tests in au1xac97c_ac97_read()
[123af9043e93cb6f235207d260d50f832cdb5439]
ASoC: nuc900: Fix a loop timeout test
[65a12b3aafed5fc59f4ce41b22b752b1729e6701]
HID: roccat: prevent an out of bounds read in kovaplus_profile_activated()
[7ad81482cad67cbe1ec808490d1ddfc420c42008]
ath9k_htc: Add a sanity check in ath9k_htc_ampdu_action()
[413fd2f5c0233d3cde391679b967c1f14cd2cb27]
cdrom: information leak in cdrom_ioctl_media_changed()
[9de4ee40547fd315d4a0ed1dd15a2fa3559ad707]
media: cpia2: Fix a couple off by one bugs
[d5ac225c7d64c9c3ef821239edc035634e594ec9]
staging: lustre: libcfs: Prevent harmless read underflow
[134aecbc25fd77645baaea5467b2a7ed8e9d1ea7]
staging: ncpfs: memory corruption in ncp_read_kernel()
[4c41aa24baa4ed338241d05494f2c595c885af8f]
staging: rts5208: Fix "seg_no" calculation in reset_ms_card()
[7f7aeea7cf30368b9fdb86dcc9d2c8a3ebc65dfb]

Daniel N Pettersson (1):
cifs: Fix autonegotiate security settings mismatch
[9aca7e454415f7878b28524e76bebe1170911a88]

Danilo Krummrich (1):
usb: quirks: add control message delay for 1b1c:1b20
[cb88a0588717ba6c756cb5972d75766b273a6817]

Dave Hansen (1):
x86/cpu: Rename "WESTMERE2" family to "NEHALEM_G"
[4b3b234f434d440fcd749b9636131b76e2ce561e]

Dave Young (1):
HID: add quirk for another PIXART OEM mouse used by HP
[01cffe9ded15c0d664e0beb33c594e00c0d57bba]

David Ahern (1):
net: Refactor rtable initialization
[d08c4f355403840fad98d9918db51a7113f38ee8]

David Matlack (1):
KVM: nVMX: mark vmcs12 pages dirty on L2 exit
[c9f04407f2e0b3fc9ff7913c65fcfcb0a4b61570]

David Rientjes (1):
kernel/relay.c: limit kmalloc size to KMALLOC_MAX_SIZE
[88913bd8ea2a75d7e460a4bed5f75e1c32660d7e]

David Woodhouse (11):
x86/cpufeature: Blacklist SPEC_CTRL/PRED_CMD on early Spectre v2 microcodes
[a5b2966364538a0e68c9fa29bc0a3a1651799035]
x86/cpufeatures: Add AMD feature bits for Speculation Control
[5d10cbc91d9eb5537998b65608441b592eec65e7]
x86/cpufeatures: Add Intel feature bits for Speculation Control
[fc67dd70adb711a45d2ef34e12d1a8be75edde61]
x86/cpufeatures: Clean up Spectre v2 related CPUID flags
[2961298efe1ea1b6fc0d7ee8b76018fa6c0bcef2]
x86/cpuid: Fix up "virtual" IBRS/IBPB/STIBP feature bits on Intel
[7fcae1118f5fd44a862aa5c3525248e35ee67c3b]
x86/msr: Add definitions for new speculation control MSRs
[1e340c60d0dd3ae07b5bedc16a0469c14b9f3410]
x86/pti: Do not enable PTI on CPUs which are not vulnerable to Meltdown
[fec9434a12f38d3aeafeb75711b71d8a1fdef621]
x86/speculation: Add basic IBPB (Indirect Branch Prediction Barrier) support
[20ffa1caecca4db8f79fe665acdeaa5af815a24d]
x86/speculation: Correct Speculation Control microcode blacklist again
[d37fc6d360a404b208547ba112e7dabb6533c7fc]
x86/speculation: Update Speculation Control microcode blacklist
[1751342095f0d2b36fa8114d8e12c5688c455ac4]
x86/speculation: Use IBRS if available before calling into firmware
[dd84441a797150dcc49298ec95c459a8891d8bb1]

Dmitry Torokhov (1):
Input: edt-ft5x06 - fix error handling for factory mode on non-M06
[4b3e910d7f430ab76dd37131bb75129878950163]

Dmitry Vyukov (1):
netfilter: ipt_CLUSTERIP: fix out-of-bounds accesses in clusterip_tg_check()
[1a38956cce5eabd7b74f94bab70265e4df83165e]

Eran Ben Elisha (1):
net/mlx4_en: Fix mixed PFC and Global pause user control requests
[6e8814ceb7e8f468659ef9253bd212c07ae19584]

Eric Biggers (15):

      NFS: reject request for id_legacy key without auxdata
         [49686cbbb3ebafe42e63868222f269d8053ead00]
      binder: check for binder_thread allocation failure in binder_poll()
         [f88982679f54f75daa5b8eff3da72508f1e7422f]
      crypto: cryptd - pass through absence of ->setkey()
         [841a3ff329713f796a63356fef6e2f72e4a3f6a3]
      crypto: hash - annotate algorithms taking optional key
         [a208fa8f33031b9e0aba44c7d1b7e68eb0cbd29e]
      crypto: hash - introduce crypto_hash_alg_has_setkey()
         [cd6ed77ad5d223dc6299fb58f62e0f5267f7e2ba]
      crypto: hash - prevent using keyed hashes without setting key
         [9fa68f620041be04720d0cbfb1bd3ddfc6310b24]
      libata: fix length validation of ATAPI-relayed SCSI commands
         [058f58e235cbe03e923b30ea7c49995a46a8725f]
      libata: remove WARN() for DMA or PIO command without data
         [9173e5e80729c8434b8d27531527c5245f4a5594]
      pipe, sysctl: drop 'min' parameter from pipe-max-size converter
         [4c2e4befb3cc9ce42d506aa537c9ab504723e98c]
      pipe, sysctl: remove pipe_proc_fn()
         [319e0a21bb7823abbb4818fe2724e572bbac77a2]
      pipe: actually allow root to exceed the pipe buffer limits
         [85c2dd5473b2718b4b63e74bfeb1ca876868e11f]
      pipe: fix off-by-one error when checking buffer limits
         [9903a91c763ecdae333a04a9d89d79d2b8966503]
      pipe: read buffer limits atomically
         [f7340761812fc10313e6fcc115e0bc4f7a799112]
      pipe: reject F_SETPIPE_SZ with size over UINT_MAX
         [96e99be40e4cff870a83233731121ec0f7f95075]
      pipe: simplify round_pipe_size()
         [c4fed5a91fadc8a277b1eda474317b501651dd3e]

Eric Dumazet (4):
l2tp: do not accept arbitrary sockets
[17cfe79a65f98abe535261856c5aef14f306dff7]
net: fix possible out-of-bound read in skb_network_protocol()
[1dfe82ebd7d8fd43dba9948fdfb31f145014baa0]
net: igmp: add a missing rcu locking section
[e7aadb27a5415e8125834b84a74477bfbee4eff5]
netfilter: IDLETIMER: be syzkaller friendly
[cfc2c740533368b96e2be5e0a4e8c3cace7d9814]

Eric W. Biederman (4):
fs: Teach path_connected to handle nfs filesystems with multiple roots.
[95dd77580ccd66a0da96e6d4696945b8cea39431]
mn10300/misalignment: Use SIGSEGV SEGV_MAPERR to report a failed user copy
[6ac1dc736b323011a55ecd1fc5897c24c4f77cbd]
signal/openrisc: Fix do_unaligned_access to send the proper signal
[500d58300571b6602341b041f97c082a461ef994]
signal/sh: Ensure si_signo is initialized in do_divide_error
[0e88bb002a9b2ee8cc3cc9478ce2dc126f849696]

Erik Veijola (1):
ALSA: usb-audio: Add a quirck for B&W PX headphones
[240a8af929c7c57dcde28682725b29cf8474e8e5]

Ernesto A . Fernández (1):
ext4: correct documentation for grpid mount option
[9f0372488cc9243018a812e8cfbf27de650b187b]

Eugene Syromiatnikov (1):
s390: fix handling of -1 in set{,fs}[gu]id16 syscalls
[6dd0d2d22aa363fec075cb2577ba273ac8462e94]

Felix Kuehling (1):
drm/ttm: Don't add swapped BOs to swap-LRU list
[fd5002d6a3c602664b07668a24df4ef7a43bf078]

Florian Fainelli (2):
net: systemport: Rewrite __bcm_sysport_tx_reclaim()
[484d802d0f2f29c335563fcac2a8facf174a1bbc]
pinctrl: Really force states during suspend/resume
[981ed1bfbc6c4660b2ddaa8392893e20a6255048]

Florian Westphal (6):
netfilter: bridge: ebt_among: add missing match size checks
[c4585a2823edf4d1326da44d1524ecbfda26bb37]
netfilter: bridge: ebt_among: add more missing match size checks
[c8d70a700a5b486bfa8e5a7d33d805389f6e59f9]
netfilter: ebtables: CONFIG_COMPAT: don't trust userland offsets
[b71812168571fa55e44cdd0254471331b9c4c4c6]
netfilter: ebtables: fix erroneous reject of last rule
[932909d9b28d27e807ff8eecb68c7748f6701628]
netfilter: ipv6: fix use-after-free Write in nf_nat_ipv6_manip_pkt
[b078556aecd791b0e5cb3a59f4c3a14273b52121]
xfrm_user: uncoditionally validate esn replay attribute struct
[d97ca5d714a5334aecadadf696875da40f1fbf3e]

Ganesh Mahendran (1):
android: binder: use VM_ALLOC to get vm area
[aac6830ec1cb681544212838911cdc57f2638216]

Geert Uytterhoeven (1):
RDMA/iwpm: Fix uninitialized error code in iwpm_send_mapinfo()
[302d6424e4a293a5761997e6c9fc3dfb1e4c355f]

Greg Kroah-Hartman (2):
USB: serial: pl2303: new device id for Chilitag
[d08dd3f3dd2ae351b793fc5b76abdbf0fd317b12]
drm: udl: Properly check framebuffer mmap offsets
[3b82a4db8eaccce735dffd50b4d4e1578099b8e8]

Greg Kurz (1):
9p/trans_virtio: discard zero-length reply
[26d99834f89e76514076d9cd06f61e56e6a509b8]

Guillaume Nault (3):

      l2tp: avoid using ->tunnel_sock for getting session's parent tunnel
         [7198c77aa05560c257ee377ec1f4796812121580]
      l2tp: don't close sessions in l2tp_tunnel_destruct()
         [765924e362d12f87786060b98a49abd91e11ea96]
      l2tp: remove l2tp_tunnel_count and l2tp_session_count
         [c7fa745d988812c4dea7dbc645f025c5bfa4917e]

Hans de Goede (10):
ASoC: rt5651: Fix regcache sync errors on resume
[2d30e9494f1ea320aaaad0cff9ddd92c87eac355]
PCI: Add function 1 DMA alias quirk for Highpoint RocketRAID 644L
[1903be8222b7c278ca897c129ce477c1dd6403a8]
USB: cdc-acm: Do not log urb submission errors on disconnect
[f0386c083c2ce85284dc0b419d7b89c8e567c09f]
ahci: Add PCI ids for Intel Bay Trail, Cherry Trail and Apollo Lake AHCI
[998008b779e424bd7513c434d0ab9c1268459009]
ahci: Add PCI-id for the Highpoint Rocketraid 644L card
[28b2182dad43f6f8fcbd167539a26714fd12bd64]
libata: Apply NOLPM quirk to Crucial M500 480 and 960GB SSDs
[62ac3f7305470e3f52f159de448bc1a771717e88]
libata: Apply NOLPM quirk to Crucial MX100 512GB SSDs
[9c7be59fc519af9081c46c48f06f2b8fadf55ad8]
libata: Make Crucial BX100 500GB LPM quirk apply to all firmware versions
[3bf7b5d6d017c27e0d3b160aafb35a8e7cfeda1f]
libata: Modify quirks for MX100 to limit NCQ_TRIM quirk to MU01 version
[d418ff56b8f2d2b296daafa8da151fe27689b757]
uas: Log error codes when logging errors
[ce39fe6fa115d9fea0112c907773a400b98d2463]

Hans van Kranenburg (1):
btrfs: alloc_chunk: fix DUP stripe size handling
[92e222df7b8f05c565009c7383321b593eca488b]

Hemant Kumar (1):
usb: f_fs: Prevent gadget unbind if it is already unbound
[ce5bf9a50daf2d9078b505aca1cea22e88ecb94a]

Horia Geantă (1):
crypto: caam - fix endless loop when DECO acquire fails
[225ece3e7dad4cfc44cca38ce7a3a80f255ea8f1]

Ilya Dryomov (1):
rbd: whitelist RBD_FEATURE_OPERATIONS feature bit
[e573427a440fd67d3f522357d7ac901d59281948]

Ingo Molnar (1):
x86/speculation: Move firmware_restrict_branch_speculation_*() from C to CPP
[d72f4e29e6d84b7ec02ae93088aa459ac70e733b]

Ioana Ciornei (1):
staging: iio: adc: remove the use of CamelCase
[5f7e280f5ae61450a7aecd9feefe3f032b6a5abf]

Ivan Delalande (1):
lkdtm: fix handle_irq_event symbol for INT_HW_IRQ_EN
[5be2a5011c039506e2862650c928acfb2e3d7b9c]

Ivan Vecera (2):
kernfs: fix regression in kernfs_fop_write caused by wrong type
[ba87977a49913129962af8ac35b0e13e0fa4382d]
net/mlx4_en: do not ignore autoneg in mlx4_en_set_pauseparam()
[278d436a476f69fc95d5c82bf61b6c2d02f4d44e]

J. Bruce Fields (1):
NFS: commit direct writes even if they fail partially
[1b8d97b0a837beaf48a8449955b52c650a7114b4]

Jack Morgenstein (1):
IB/mlx4: Fix incorrectly releasing steerable UD QPs when have only ETH ports
[852f6927594d0d3e8632c889b2ab38cbc46476ad]

Jack Stocker (1):
Add delay-init quirk for Corsair K70 RGB keyboards
[7a1646d922577b5b48c0d222e03831141664bb59]

Jake Daryll Obina (1):
jffs2: Fix use-after-free bug in jffs2_iget()'s error handling path
[5bdd0c6f89fba430e18d636493398389dadc3b17]

Jakub Kicinski (1):
net: fix race on decreasing number of TX queues
[ac5b70198adc25c73fba28de4f78adcee8f6be0b]

James Chapman (5):
l2tp: don't use inet_shutdown on ppp session destroy
[225eb26489d05c679a4c4197ffcb81c81e9dcaf4]
l2tp: don't use inet_shutdown on tunnel destroy
[76a6abdb2513ad4ea0ded55d2c66160491f2e848]
l2tp: fix race in pppol2tp_release with session object destroy
[d02ba2a6110c530a32926af8ad441111774d2893]
l2tp: fix races with tunnel socket close
[d00fa9adc528c1b0e64d532556764852df8bd7b9]
l2tp: fix tunnel lookup use-after-free race
[28f5bfb819195ad9c2eb9486babe7b0e4efe925f]

James Hogan (2):

      EDAC, octeon: Fix an uninitialized variable warning
         [544e92581a2ac44607d7cc602c6b54d18656f56d]
      MIPS: Fix clean of vmlinuz.{32,ecoff,bin,srec}
         [5f2483eb2423152445b39f2db59d372f523e664e]

James Ralston (1):
ahci: Remove Device ID for Intel Sunrise Point PCH
[46319e13581a6c442b0a0e5a3bd5d9af4496f252]

Jan Beulich (1):

      x86/mm: Fix {pmd,pud}_{set,clear}_flags()
         [842cef9113c2120f74f645111ded1e020193d84c]

Jan Chochol (1):
nfs: Do not convert nfs_idmap_cache_timeout to jiffies
[cbebc6ef4fc830f4040d4140bf53484812d5d5d9]

Jan-Marek Glogowski (1):
ALSA: hda/realtek: PCI quirk for Fujitsu U7x7
[fdcc968a3b290407bcba9d4c90e2fba6d8d928f1]

Jason Gunthorpe (1):
sctp: Fix mangled IPv4 addresses on a IPv6 listening socket
[9302d7bb0c5cd46be5706859301f18c137b2439f]

Jason Wang (1):
vhost_net: stop device during reset owner
[4cd879515d686849eec5f718aeac62a70b067d82]

Jason Yan (5):
ata: do not schedule hot plug if it is a sas host
[6f54120e17e311fd7ac42b9ec2a0611caa5b46ad]
scsi: libsas: direct call probe and destruct
[0558f33c06bb910e2879e355192227a8e8f0219d]
scsi: libsas: fix error when getting phy events
[2b23d9509fd7174b362482cf5f3b5f9a2265bc33]
scsi: libsas: fix memory leak in sas_smp_get_phy_events()
[4a491b1ab11ca0556d2fda1ff1301e862a2d44c4]
scsi: libsas: remove the numbering for each event enum
[0d78f969b10f27e0be34210d482a01e1ee92994c]

Jean Delvare (1):
firmware: dmi_scan: Fix handling of empty DMI strings
[a7770ae194569e96a93c48aceb304edded9cc648]

Jens Axboe (1):
aio: fix serial draining in exit_aio()
[dc48e56d761610da4ea1088d1bea0a030b8e3e43]

Jeremy Boone (4):
tpm: fix potential buffer overruns caused by bit glitches on the bus
[3be23274755ee85771270a23af7691dc9b3a95db]
tpm_i2c_infineon: fix potential buffer overruns caused by bit glitches on the bus
[9b8cb28d7c62568a5916bdd7ea1c9176d7f8f2ed]
tpm_i2c_nuvoton: fix potential buffer overruns caused by bit glitches on the bus
[f9d4d9b5a5ef2f017bc344fb65a58a902517173b]
tpm_tis: fix potential buffer overruns caused by bit glitches on the bus
[6bb320ca4a4a7b5b3db8c8d7250cc40002046878]

Jia-Ju Bai (1):
USB: serial: io_edgeport: fix possible sleep-in-atomic
[c7b8f77872c73f69a16528a9eb87afefcccdc18b]

Jim Mattson (1):
KVM: nVMX: Eliminate vmcs02 pool
[de3a0021a60635de96aa92713c1a31a96747d72c]

Jiri Bohac (1):
x86/gart: Exclude GART aperture from vmcore
[2a3e83c6f96c513f43ce5a8c9034608ea584a255]

Joe Lawrence (3):
pipe: add proc_dopipe_max_size() to safely assign pipe_max_size
[7a8d181949fb2c16be00f8cdb354794a30e46b39]
pipe: avoid round_pipe_size() nr_pages overflow on 32-bit
[d3f14c485867cfb2e0c48aa88c41d0ef4bf5209c]
sysctl: check for UINT_MAX before unsigned int min/max
[fb910c42ccebf853c29296185c45c11164a56098]

Joel Fernandes (1):
staging: android: ashmem: Fix lockdep issue during llseek
[cb57469c9573f6018cd1302953dd45d6e05aba7b]

Johan Hovold (5):
USB: serial: add Medtronic CareLink USB driver
[cff9c2339a6d5105d7f6b1f9a96dd1d239cc76ac]
USB: serial: add Novatel Wireless GPS driver
[c5cd24d7b179a415df263e5b18b72f6e3aaf81e0]
USB: serial: add support for multi-port simple drivers
[b9f040389e23fb95fde36cb0a3c2c516fb3e9d1c]
USB: serial: simple: add Motorola Tetra driver
[46fe895e22ab3845515ec06b01eaf1282b342e29]
video: fbdev: atmel_lcdfb: fix display-timings lookup
[9cb18db0701f6b74f0c45c23ad767b3ebebe37f6]

Johannes Berg (1):
regulatory: add NUL to request alpha2
[657308f73e674e86b60509a430a46e569bf02846]

John Crispin (1):
MIPS: ralink: Don't set pm_power_off
[81ab9f6c5ff8565e4cba330e340a8979a10521d7]

Jonas Danielsson (1):
tty/serial: atmel: add new version check for usart
[fd63a8903a2c40425a9811c3371dd4d0f42c0ad3]

Ju Hyung Park (1):
libata: Enable queued TRIM for Samsung SSD 860
[ca6bfcb2f6d9deab3924bf901e73622a94900473]

Juergen Gross (2):
x86/xen: Zero MSR_IA32_SPEC_CTRL before suspend
[71c208dd54ab971036d83ff6d9837bae4976e623]
x86/xen: init %gs very early to avoid page faults with stack protector
[4f277295e54c5b7340e48efea3fc5cc21a2872b7]

Julia Lawall (3):
USB: usbmon: remove assignment from IS_ERR argument
[46c236dc7d1212d7417e6fb0317f91c44c719322]
drivers: video: fbdev: atmel_lcdfb.c: fix error return code
[6c131850eca653344c41d68ce87f3ab5a89af89e]
drm/radeon: adjust tested variable
[3a61b527b4e1f285d21b6e9e623dc45cf8bb391f]

Julian Wiedmann (2):
s390/qeth: fix SETIP command handling
[1c5b2216fbb973a9410e0b06389740b5c1289171]
s390/qeth: free netdevice when removing a card
[6be687395b3124f002a653c1a50b3260222b3cd7]

Julien Gomes (1):
tun: allow positive return values on dev_get_valid_name() call
[5c25f65fd1e42685f7ccd80e0621829c105785d9]

Justin Chen (1):
MIPS: BMIPS: Do not mask IPIs during suspend
[06a3f0c9f2725f5d7c63c4203839373c9bd00c28]

Kai-Heng Feng (3):
drm/edid: Add 6 bpc quirk for CPT panel in Asus UX303LA
[06998a756a3865817b87a129a7e5d5bb66dc1ec3]
libata: disable LPM for Crucial BX100 SSD 500GB drive
[b17e5729a630d8326a48ec34ef02e6b4464a6aef]
xhci: Fix front USB ports on ASUS PRIME B350M-A
[191edc5e2e515aab1075a3f0ef23599e80be5f59]

Kamil Konieczny (1):
crypto: s5p-sss - Fix kernel Oops in AES-ECB mode
[c927b080c67e3e97193c81fc1d27f4251bf4e036]

KarimAllah Ahmed (3):
KVM/SVM: Allow direct access to MSR_IA32_SPEC_CTRL
[b2ac58f90540e39324e7a29a7ad471407ae0bf48]
KVM/VMX: Allow direct access to MSR_IA32_SPEC_CTRL
[d28b387fb74da95d69d2615732f50cceb38e9a4d]
KVM/VMX: Emulate MSR_IA32_ARCH_CAPABILITIES
[28c1c9fabf48d6ad596273a11c46e0d0da3e14cd]

Karsten Koop (1):
usb: ldusb: add PIDs for new CASSY devices supported by this driver
[52ad2bd8918158266fc88a05f95429b56b6a33c5]

Kees Cook (1):
NFC: llcp: Limit size of SDP URI
[fe9c842695e26d8116b61b80bfb905356f07834b]

Kirill Marinushkin (1):
ALSA: usb-audio: Fix parsing descriptor of UAC2 processing unit
[a6618f4aedb2b60932d766bd82ae7ce866e842aa]

Konrad Rzeszutek Wilk (1):
x86/spectre_v2: Don't check microcode versions when running under hypervisors
[36268223c1e9981d6cfc33aff8520b3bde4b8114]

Lars-Peter Clausen (1):
iio: adis_lib: Initialize trigger before requesting interrupt
[f027e0b3a774e10302207e91d304bbf99e3a8b36]

Lassi Ylikojola (1):
ALSA: usb-audio: add implicit fb quirk for Behringer UFX1204
[5e35dc0338d85ccebacf3f77eca1e5dea73155e8]

Leon Romanovsky (11):
RDMA/mlx5: Avoid memory leak in case of XRCD dealloc failure
[b081808a66345ba725b77ecd8d759bee874cd937]
RDMA/mlx5: Fix integer overflow while resizing CQ
[28e9091e3119933c38933cb8fc48d5618eb784c8]
RDMA/ucma: Check AF family prior resolving address
[2975d5de6428ff6d9317e9948f0968f7d42e5d74]
RDMA/ucma: Check that device exists prior to accessing it
[c8d3bcbfc5eab3f01cf373d039af725f3b488813]
RDMA/ucma: Check that device is connected prior to access it
[4b658d1bbc16605330694bb3ef2570c465ef383d]
RDMA/ucma: Check that user doesn't overflow QP state
[a5880b84430316e3e1c1f5d23aa32ec6000cc717]
RDMA/ucma: Don't allow join attempts for unsupported AF family
[0c81ffc60d5280991773d17e84bda605387148b1]
RDMA/ucma: Ensure that CM_ID exists prior to access it
[e8980d67d6017c8eee8f9c35f782c4bd68e004c9]
RDMA/ucma: Fix access to non-initialized CM_ID object
[7688f2c3bbf55e52388e37ac5d63ca471a7712e1]
RDMA/ucma: Fix use-after-free access in ucma_close
[ed65a4dc22083e73bac599ded6a262318cad7baf]
RDMA/ucma: Limit possible option size
[6a21dfc0d0db7b7e0acedce67ca533a6eb19283c]

Linus Lüssing (2):
batman-adv: fix multicast-via-unicast transmission with AP isolation
[f8fb3419ead44f9a3136995acd24e35da4525177]
batman-adv: fix packet loss for broadcasted DHCP packets to a server
[a752c0a4524889cdc0765925258fd1fd72344100]

Linus Torvalds (3):
kvm/x86: fix icebp instruction handling
[32d43cd391bacb5f0814c2624399a5dad3501d09]
perf/hwbp: Simplify the perf-hwbp code, fix documentation
[f67b15037a7a50c57f72e69a6d59941ad90a0f0f]
tty: vt: fix up tabstops properly
[f1869a890cdedb92a3fab969db5d0fd982850273]

Linus Walleij (1):
mtd: jedec_probe: Fix crash in jedec_read_mfr()
[87a73eb5b56fd6e07c8e499fe8608ef2d8912b82]

Liu Bo (4):

      Btrfs: fix crash due to not cleaning up tree log block's dirty bits
         [1846430c24d66e85cc58286b3319c82cd54debb2]
      Btrfs: fix deadlock in run_delalloc_nocow
         [e89166990f11c3f21e1649d760dd35f9e410321c]
      Btrfs: fix extent state leak from tree log
         [55237a5f2431a72435e3ed39e4306e973c0446b7]
      Btrfs: fix use-after-free on root->orphan_block_rsv
         [1a932ef4e47984dee227834667b5ff5a334e4805]

Lukas Czerner (1):
ext4: fix bitmap position validation
[22be37acce25d66ecf6403fc8f44df9c5ded2372]

Lukas Wunner (5):
Revert "apple-gmux: lock iGP IO to protect from vgaarb changes"
[d6fa7588fd7a8def4c747c0c574ce85d453e3788]
drm/nouveau: Fix deadlock on runtime suspend
[d61a5c1063515e855bedb1b81e20e50b0ac3541e]
drm/radeon: Fix deadlock on runtime suspend
[15734feff2bdac24aa3266c437cffa42851990e3]
drm: Allow determining if current task is output poll worker
[25c058ccaf2ebbc3e250ec1e199e161f91fe27d4]
workqueue: Allow retrieval of current task's work struct
[27d4ee03078aba88c5e07dcc4917e8d01d046f38]

Maciej W. Rozycki (1):
MIPS: Normalise code flow in the CpU exception handler
[27e28e8ec47a5ce335ebf25d34ca356c80635908]

Malcolm Priestley (2):

      media: dvb-usb-v2: lmedm04: Improve logic checking of warm  start
         [3d932ee27e852e4904647f15b64dedca51187ad7]
      media: dvb-usb-v2: lmedm04: move ts2020 attach to  dm04_lme2510_tuner
         [7bf7a7116ed313c601307f7e585419369926ab05]

Marc Kleine-Budde (1):
slip: sl_alloc(): remove unused parameter "dev_t line"
[936e5d8bdfa72577e28ea671d9e2ee4fef0d6b3e]

Marc Zyngier (2):
arm64: KVM: Increment PC after handling an SMC trap
[f5115e8869e1dfafac0e414b4f1664f3a84a4683]
arm: KVM: Fix SMCCC handling of unimplemented SMC/HVC calls
[20e8175d246e9f9deb377f2784b3e7dfb2ad3e86]

Mark Rutland (1):
arm64: remove __die()'s stack dump
[c5bc503cbeee8586395aa541d2b53c69c3dd6930]

Masahiro Yamada (1):
mmc: sdhci: export sdhci_execute_tuning()
[85a882c2e91d3655927ecdc1db823d1420a65b8f]

Masami Hiramatsu (1):
tracing: probeevent: Fix to support minus offset from symbol
[c5d343b6b7badd1f5fe0873eff2e8d63a193e732]

Masatake YAMATO (1):
route: remove unsed variable in __mkroute_input
[cb1c61680d29a054b91a23c7a504cea8a72bdcff]

Matt Redfearn (1):
MIPS: TXx9: use IS_BUILTIN() for CONFIG_LEDS_CLASS
[0cde5b44a30f1daaef1c34e08191239dc63271c4]

Matthew Wilcox (1):
cifs: Fix missing put_xid in cifs_file_strict_mmap
[f04a703c3d613845ae3141bfaf223489de8ab3eb]

Matthias Schiffer (4):
batman-adv: fix header size check in batadv_dbg_arp()
[6f27d2c2a8c236d296201c19abb8533ec20d212b]
batman-adv: fix packet checksum in receive path
[abd6360591d3f8259f41c34e31ac4826dfe621b8]
batman-adv: invalidate checksum on fragment reassembly
[3bf2a09da956b43ecfaa630a2ef9a477f991a46a]
batman-adv: update data pointers after skb_cow()
[bc44b78157f621ff2a2618fe287a827bcb094ac4]

Mauro Carvalho Chehab (1):

      media: cxusb, dib0700: ignore XC2028_I2C_FLUSH
         [9893b905e743ded332575ca04486bd586c0772f7]

Max Filippov (1):
xtensa: fix futex_atomic_cmpxchg_inatomic
[ca47480921587ae30417dd234a9f79af188e3666]

Mel Gorman (1):
mm: pin address_space before dereferencing it while isolating an LRU page
[69d763fc6d3aee787a3e8c8c35092b4f4960fa5d]

Michael Kerrisk (8):
pipe: cap initial pipe capacity according to pipe-max-size limit
[086e774a57fba4695f14383c0818994c0b31da7c]
pipe: fix limit checking in alloc_pipe_info()
[a005ca0e6813e1d796a7422a7e31d8b8d6555df1]
pipe: fix limit checking in pipe_set_size()
[b0b91d18e2e97b741b294af9333824ecc3fadfd8]
pipe: make account_pipe_buffers() return a value, and use it
[9c87bcf0a31b338dc8a69a5d251a037565a94e13]
pipe: move limit checking logic into pipe_set_size()
[d37d41666408102bf0ac8e48d8efdce7b809e5f6]
pipe: refactor argument for account_pipe_buffers()
[3734a13b96ebf039b293d8d37a934fd1bd9e03ab]
pipe: relocate round_pipe_size() above pipe_set_size()
[f491bd71118beba608d39ac2d5f1530e1160cd2e]
pipe: simplify logic in alloc_pipe_info()
[09b4d1990094dd22c27fb0163534db419458569c]

Michael Lyle (1):
bcache: don't attach backing with duplicate UUID
[86755b7a96faed57f910f9e6b8061e019ac1ec08]

Michael Weiser (2):
arm64: Disable unhandled signal log messages by default
[5ee39a71fd89ab7240c5339d04161c44a8e03269]
arm64: Remove unimplemented syscall log message
[1962682d2b2fbe6cfa995a85c53c069fadda473e]

Michel Dänzer (1):
drm/radeon: Don't turn off DP sink when disconnected
[2681bc79eeb640562c932007bfebbbdc55bf6a7d]

Mika Westerberg (1):
ahci: Add Intel Cannon Lake PCH-H PCI ID
[f919dde0772a894c693a1eeabc77df69d6a9b937]

Mike Kravetz (2):
hugetlbfs: check for pgoff value overflow
[63489f8e821144000e0bdca7e65a8d1cc23a7ee7]
hugetlbfs: fix offset overflow in hugetlbfs mmap
[045c7a3f53d9403b62d396b6d051c4be5044cdb4]

Mikulas Patocka (2):
alpha: fix crash if pthread_create races with signal delivery
[21ffceda1c8b3807615c40d440d7815e0c85d366]
alpha: fix reboot on Avanti platform
[55fc633c41a08ce9244ff5f528f420b16b1e04d6]

Mimi Zohar (1):
ima: relax requiring a file signature for new files with zero length
[b7e27bc1d42e8e0cc58b602b529c25cd0071b336]

Miquel Raynal (1):
mtd: nand: Fix nand_do_read_oob() return value
[87e89ce8d0d14f573c068c61bec2117751fb5103]

Mulhern (1):
dm thin: fix documentation relative to low water mark threshold
[9b28a1102efc75d81298198166ead87d643a29ce]

Namjae Jeon (1):
cifs: fix memory leak when password is supplied multiple times
[d6ccf4997e62fb6629f9f003980dca5292138b7b]

Nathan Fontenot (1):
powerpc/numa: Invalidate numa_cpu_lookup_table on cpu remove
[1d9a090783bef19fe8cdec878620d22f05191316]

NeilBrown (1):
MIPS: ralink: Remove ralink_halt()
[891731f6a5dbe508d12443175a7e166a2fba616a]

Nicholas Piggin (1):
powerpc/64: Don't trace irqs-off at interrupt return to soft-disabled context
[acb1feab320e38588fccc568e3767761f494976f]

Nicolas Dichtel (2):
netlink: avoid a double skb free in genlmsg_mcast()
[02a2385f37a7c6594c9d89b64c4a1451276f08eb]
netlink: ensure to loop over all netns in genlmsg_multicast_allns()
[cb9f7a9a5c96a773bbc9c70660dc600cfff82f82]

Nicolas Pitre (1):
console/dummy: leave .con_font_get set to NULL
[724ba8b30b044aa0d94b1cd374fc15806cdd6f18]

Nikola Ciprich (1):
serial: 8250_pci: Add Brainboxes UC-260 4 port serial device
[9f2068f35729948bde84d87a40d135015911345d]

Nikolay Borisov (1):
btrfs: Handle btrfs_set_extent_delalloc failure in fixup worker
[f3038ee3a3f1017a1cbe9907e31fa12d366c5dcb]

OKAMOTO Yoshiaki (1):
usb: option: Add support for FS040U modem
[69341bd15018da0a662847e210f9b2380c71e623]

Oleg Nesterov (2):

      aio: change exit_aio() to load mm->ioctx_table once and avoid rcu_read_lock()
         [4b70ac5fd9b58bfaa5f25b4ea48f528aefbf3308]
      aio: kill the misleading rcu read locks in ioctx_add_table() and kill_ioctx()
         [855ef0dec7271ff7be7381feaaf3f4aed80bd503]

Oliver Neukum (3):
CDC-ACM: apply quirk for card reader
[df1cc78a52491f71d8170d513d0f6f114faa1bda]
uas: fix comparison for error code
[9a513c905bb95bef79d96feb08621c1ec8d8c4bb]
usb: uas: unconditionally bring back host after reset
[cbeef22fd611c4f47c494b821b2b105b8af970bb]

Paolo Abeni (7):
dn_getsockoptdecnet: move nf_{get/set}sockopt outside sock lock
[dfec091439bb2acf763497cfc58f2bdfc67c56b7]
ipv6: the entire IPv6 header chain must fit the first fragment
[10b8a3de603df7b96004179b1b33b1708c76d144]
l2tp: fix races with ipv4-mapped ipv6 addresses
[b954f94023dcc61388c8384f0f14eb8e42c863c5]
netfilter: drop outermost socket lock in getsockopt()
[01ea306f2ac2baff98d472da719193e738759d93]
netfilter: nat: cope with negative port range
[db57ccf0f2f4624b4c4758379f8165277504fbd7]
netfilter: on sockopt() acquire sock lock only in the required scope
[3f34cfae1238848fd53f25e5c8fd59da57901f4b]
netfilter: x_tables: fix missing timer initialization in xt_LED
[10414014bc085aac9f787a5890b33b5605fbcfc4]

Paolo Bonzini (6):
KVM/VMX: Optimize vmx_vcpu_run() and svm_vcpu_run() by marking the RDMSR path as unlikely()
[946fbbc13dce68902f64515b610eeb2a6c3d7a64]
KVM/x86: Remove indirect MSR op calls from SPEC_CTRL
[ecb586bd29c99fb4de599dec388658e74388daad]
KVM: VMX: introduce alloc_loaded_vmcs
[f21f165ef922c2146cc5bdc620f542953c41714b]
KVM: VMX: make MSR bitmaps per-VCPU
[904e14fb7cb96401a7dc803ca2863fd5ba32ffe6]
KVM: x86: pass host_initiated to functions that read MSRs
[609e36d372ad9329269e4a1467bd35311893d1d6]
KVM: x86: rename update_db_bp_intercept to update_bp_intercept
[a96036b8ef7df9f10cd575c0d78359bd33188e8e]

Parav Pandit (1):
RDMA/cma: Use correct size when writing netlink stats
[7baaa49af3716fb31877c61f59b74d029ce15b75]

Pete Zaitcev (1):
usb: usbmon: Read text within supplied buffer size
[a5f596830e27e15f7a0ecd6be55e433d776986d8]

Peter Malone (1):
fbdev: Fixing arbitrary kernel leak in case FBIOGETCMAP_SPARC in sbusfb_ioctl_helper().
[250c6c49e3b68756b14983c076183568636e2bde]

Peter Zijlstra (1):
x86/speculation: Add <asm/msr-index.h> dependency
[ea00f301285ea2f07393678cd2b6057878320c9d]

Petr Machata (1):
ip_tunnel: Emit events for post-register MTU changes
[f6cc9c054e77b9a28d4594bcc201697edb21dfd2]

Raghava Aditya Renukunta (1):
scsi: aacraid: Fix udev inquiry race condition
[f4e8708d3104437fd7716e957f38c265b0c509ef]

Rasmus Villemoes (2):
kernel/async.c: revert "async: simplify lowest_in_progress()"
[4f7e988e63e336827f4150de48163bed05d653bd]
nospec: Allow index argument to have const-qualified type
[b98c6a160a057d5686a8c54c79cc6c8c94a7d0c8]

Roger Pau Monne (1):
xen/pirq: fix error path cleanup when binding MSIs
[910f8befdf5bccf25287d9f1743e3e546bcb7ce0]

Sabrina Dubroca (1):
ipv4: lock mtu in fnhe when received PMTU < net.ipv4.route.min_pmtu
[d52e5a7e7ca49457dd31fc8b42fb7c0d58a31221]

Scott Lawson (1):
AHCI: Remove obsolete Intel Lewisburg SATA RAID device IDs
[8ba559fd09bcf4e87faad3efa465dacf04c076c9]

Scott Mayhew (1):
nfs/pnfs: fix nfs_direct_req ref leak when i/o falls back to the mds
[ba4a76f703ab7eb72941fdaac848502073d6e9ee]

SeongJae Park (2):
rcutorture/configinit: Fix build directory error message
[2adfa4210f8f35cdfb4e08318cc06b99752964c2]
rcutorture/kvm.sh: Use consistent help text for --qemu-args
[8dcd6f3fe206c0bb8996e59386a04027b1c2fb9b]

Sergey Senozhatsky (1):
arm64: do not use print_symbol()
[4ef7963843d3243260aa335dfb9cb2fede06aacf]

Seunghun Han (1):
x86/MCE: Serialize sysfs changes
[b3b7c4795ccab5be71f080774c45bbbcc75c2aaf]

Shaohua Li (1):
ata: Add a new flag to destinguish sas controller
[5067c0469c643512f24786990e315f9c15cc7d24]

Shawn Lin (2):
mmc: dw_mmc: Factor out dw_mci_init_slot_caps
[a4faa4929ed3be15e2d500d2405f992f6dedc8eb]
mmc: dw_mmc: Fix out-of-bounds access for slot's caps
[0d84b9e5631d923744767dc6608672df906dd092]

Shuah Khan (3):
usbip: keep usbip_device sockfd state in sync with tcp_socket
[009f41aed4b3e11e6dc1e3c07377a10c20f1a5ed]
usbip: list: don't list devices attached to vhci_hcd
[ef824501f50846589f02173d73ce3fe6021a9d2a]
usbip: prevent bind loops on devices attached to vhci_hcd
[ef54cf0c600fb8f5737fb001a9e357edda1a1de8]

Simon Shields (1):
ARM: dts: exynos: Correct Trats2 panel reset line
[1b377924841df1e13ab5b225be3a83f807a92b52]

Stefan Agner (1):
spi: imx: do not access registers while clocks disabled
[d593574aff0ab846136190b1729c151c736727ec]

Stefan Roese (1):
ALSA: pcm: Use dma_bytes as size parameter in dma_mmap_coherent()
[9066ae7ff5d89c0b5daa271e2d573540097a94fa]

Stefan Windfeldt-Prytz (1):
iio: buffer: check if a buffer has been set up when poll is called
[4cd140bda6494543f1c1b0ccceceaa44b676eef6]

Stefano Brivio (3):
ip_tunnel: Clamp MTU to bounds on new link
[24fc79798b8ddfd46f2dd363a8d29072c083b977]
vti4: Don't count header length twice on tunnel setup
[dd1df24737727e119c263acf1be2a92763938297]
vti4: Don't override MTU passed on link creation via IFLA_MTU
[03080e5ec72740c1a62e6730f2a5f3f114f11b19]

Stephan Mueller (1):
crypto: af_alg - whitelist mask and type
[bb30b8848c85e18ca7e371d0a869e94b3e383bdf]

Sven Eckelmann (2):
batman-adv: Fix internal interface indices types
[f22e08932c2960f29b5e828e745c9f3fb7c1bb86]
batman-adv: Fix skbuff rcsum on packet reroute
[fc04fdb2c8a894283259f5621d31d75610701091]

Takashi Iwai (8):
ALSA: aloop: Fix access to not-yet-ready substream via cable
[8e6b1a72a75bb5067ccb6b56d8ca4aa3a300a64e]
ALSA: aloop: Sync stale timer before release
[67a01afaf3d34893cf7d2ea19b34555d6abb7cb0]
ALSA: hda/realtek - Always immediately update mute LED with pin VREF
[e40bdb03d3cd7da66bd0bc1e40cbcfb49351265c]
ALSA: seq: Clear client entry before deleting else at closing
[a2ff19f7b70118ced291a28d5313469914de451b]
ALSA: seq: Don't allow resizing pool in use
[d85739367c6d56e475c281945c68fdb05ca74b4c]
ALSA: seq: Fix possible UAF in snd_seq_check_queue()
[d0f833065221cbfcbadf19fd4102bcfa9330006a]
ALSA: seq: Fix racy pool initializations
[d15d662e89fc667b90cd294b0eb45694e33144da]
ALSA: seq: More protection for concurrent write and ioctl races
[7bd80091567789f1c0cb70eb4737aac8bcd2b6b9]

Tang Junhui (1):
bcache: fix crashes in duplicate cache device register
[cc40daf91bdddbba72a4a8cd0860640e06668309]

Tariq Toukan (1):
net/mlx4_core: Cleanup FMR unmapping flow
[fd4a3e2828b4ca35aef40e5bdc1ed7d87b3cb50a]

Teijo Kinnunen (1):
USB: storage: Add JMicron bridge 152d:2567 to unusual_devs.h
[5126a504b63d82785eaece3a9c30c660b313785a]

Tejun Heo (3):

      fs/aio: Add explicit RCU grace period when freeing kioctx
         [a6d7cff472eea87d96899a20fa718d2bab7109f3]
      fs/aio: Use RCU accessors for kioctx_table->table[]
         [d0264c01e7587001a8c4608a5d1818dba9a4c11a]
      tty: make n_tty_read() always abort if hangup is in progress
         [28b0f8a6962a24ed21737578f3b1b07424635c9e]

Theodore Ts'o (2):
ext4: add validity checks for bitmap block numbers
[7dac4a1726a9c64a517d595c40e95e2d0d135f6f]
ext4: fail ext4_iget for root directory if unallocated
[8e4b5eae5decd9dfe5a4ee369c22028f90ab4c44]

Thinh Nguyen (1):
usb: dwc3: gadget: Set maxpacket size for ep0 IN
[6180026341e852a250e1f97ebdcf71684a3c81b9]

Thomas Gleixner (1):
posix-timers: Protect posix clock array access against speculation
[19b558db12f9f4e45a22012bae7b4783e62224da]

Thomas Richter (1):
perf annotate: Fix objdump comment parsing for Intel mov dissassembly
[35a8a148d8c1ee9e5ae18f9565a880490f816f89]

Tim Chen (1):
x86/speculation: Use Indirect Branch Prediction Barrier in context switch
[18bf3c3ea8ece8f03b6fc58508f2dfd23c7711c7]

Tobias Jordan (1):
spi: sun6i: disable/unprepare clocks on remove
[2d9bbd02c54094ceffa555143b0d68cd06504d63]

Todd Kjos (1):
binder: replace "%p" with "%pK"
[8ca86f1639ec5890d400fff9211aca22d0a392eb]

Tony Luck (1):
x86/MCE: Save microcode revision in machine check records
[fa94d0c6e0f3431523f5701084d799c77c7d4a4f]

Toshiaki Makita (2):
net: Fix untag for vlan packets without ethernet header
[ae4745730cf8e693d354ccd4dbaf59ea440c09a9]
net: Fix vlan untag for bridge and vlan_dev with reorder_hdr off
[4bbb3e0e8239f9079bf1fe20b3c0cb598714ae61]

Trond Myklebust (2):
NFS: Add a cond_resched() to nfs_commit_release_pages()
[7f1bda447c9bd48b415acedba6b830f61591601f]
NFS: Fix 2 use after free issues in the I/O code
[196639ebbe63a037fe9a80669140bd292d8bcd80]

Tyrel Datwyler (1):
scsi: ibmvfc: fix misdefined reserved field in ibmvfc_fcp_rsp_info
[c39813652700f3df552b6557530f1e5f782dbe2f]

Ulf Magnusson (1):

      ARM: mvebu: Fix broken PL310_ERRATA_753970 selects
         [8aa36a8dcde3183d84db7b0d622ffddcebb61077]

Ulrich Hecht (1):
serial: sh-sci: prevent lockup on full TTY buffers
[7842055bfce4bf0170d0f61df8b2add8399697be]

Vinicius Costa Gomes (1):
skbuff: Fix not waking applications when errors are enqueued
[6e5d58fdc9bedd0255a8781b258f10bbdc63e975]

Viresh Kumar (4):
arm: spear13xx: Fix dmas cells
[cdd10409914184c7eee5ae3e11beb890c9c16c61]
arm: spear13xx: Fix spics gpio controller's warning
[f8975cb1b8a36d0839b6365235778dd9df1d04ca]
arm: spear600: Add missing interrupt-parent of rtc
[6ffb5b4f248fe53e0361b8cbc2a523b432566442]
cpufreq: s3c24xx: Fix broken s3c_cpufreq_init()
[0373ca74831b0f93cd4cdbf7ad3aec3c33a479a5]

Wang Nan (1):
x86/traps: Enable DEBUG_STACK after cpu_init() for TRAP_DB/BP
[b4d8327024637cb2a1f7910dcb5d0ad7a096f473]

Wanpeng Li (1):
KVM: mmu: Fix overlap between public and private memslots
[b28676bb8ae4569cced423dc2a88f7cb319d5379]

Wei Yongjun (1):
mtd: ubi: wl: Fix error return code in ubi_wl_init()
[7233982ade15eeac05c6f351e8d347406e6bcd2f]

Will Deacon (2):
arm64: __show_regs: Only resolve kernel symbols when running at EL1
[a06f818a70de21b4b3b4186816094208fc7accf9]
arm64: traps: Don't print stack or raw PC/LR values in backtraces
[a25ffd3a6302a67814280274d8f1aa4ae2ea4b59]

Xin Long (4):
bonding: fix the err path for dev hwaddr sync in bond_enslave
[5c78f6bfae2b10ff70e21d343e64584ea6280c26]
bonding: move dev_mc_sync after master_upper_dev_link in bond_enslave
[ae42cc62a9f07f1f6979054ed92606b9c30f4a2e]
bonding: process the err returned by dev_set_allmulti properly in bond_enslave
[9f5a90c107741b864398f4ac0014711a8c1d8474]
bridge: check brport attr show in brport_show
[1b12580af1d0677c3c3a19e35bfe5d59b03f737f]

Yisheng Xie (2):
mm/mempolicy.c: avoid use uninitialized preferred_node
[8970a63e965b43288c4f5f40efbc2bbf80de7f16]
staging: android: ashmem: Fix possible deadlock in ashmem_ioctl
[740a5759bf222332fbb5eda42f89aa25ba38f9b2]

Yufen Yu (1):
md raid10: fix NULL deference in handle_write_completed()
[01a69cab01c184d3786af09e9339311123d63d22]

Yunlei He (1):
f2fs: fix a panic caused by NULL flush_cmd_control
[d4fdf8ba0e5808ba9ad6b44337783bd9935e0982]

Zhang Bo (1):
Input: matrix_keypad - fix race when disabling interrupts
[ea4f7bd2aca9f68470e9aac0fc9432fd180b1fe7]

Zhouyi Zhou (1):
ext4: save error to disk in __ext4_grp_locked_error()
[06f29cc81f0350261f59643a505010531130eea0]

Zygo Blaxell (1):

      btrfs: remove spurious WARN_ON(ref->count < 0) in find_parent_nodes
         [c8195a7b1ad5648857ce20ba24f384faed8512bc]
 Documentation/device-mapper/thin-provisioning.txt  |   8 +-
 Documentation/devicetree/bindings/dma/snps-dma.txt |   2 +-
 Documentation/filesystems/ext4.txt                 |   2 +-
 Makefile                                           |   4 +-
 arch/alpha/kernel/pci_impl.h                       |   3 +-
 arch/alpha/kernel/process.c                        |   3 +-
 arch/arm/boot/dts/exynos4412-trats2.dts            |   2 +-
 arch/arm/boot/dts/omap3-n900.dts                   |   4 +-
 arch/arm/boot/dts/spear1310-evb.dts                |   2 +-
 arch/arm/boot/dts/spear1340.dtsi                   |   4 +-
 arch/arm/boot/dts/spear13xx.dtsi                   |   6 +-
 arch/arm/boot/dts/spear600.dtsi                    |   1 +
 arch/arm/kvm/handle_exit.c                         |  13 +-
 arch/arm/mach-mvebu/Kconfig                        |   4 +-
 arch/arm/xen/enlighten.c                           |   1 +
 arch/arm64/kernel/process.c                        |  16 +-
 arch/arm64/kernel/traps.c                          |  58 +-
 arch/arm64/kvm/handle_exit.c                       |   9 +
 arch/ia64/scripts/unwcheck.py                      |  16 +-
 arch/mips/boot/compressed/Makefile                 |   6 +-
 arch/mips/kernel/smp-bmips.c                       |   8 +-
 arch/mips/kernel/traps.c                           |  15 +-
 arch/mips/ralink/reset.c                           |   8 -
 arch/mips/txx9/rbtx4939/setup.c                    |   4 +-
 arch/mn10300/mm/misalignment.c                     |   2 +-
 arch/openrisc/kernel/traps.c                       |  10 +-
 arch/powerpc/include/asm/kvm_book3s.h              |   6 +-
 arch/powerpc/include/asm/topology.h                |   8 +
 arch/powerpc/kernel/entry_64.S                     |  10 +-
 arch/powerpc/kvm/book3s_interrupts.S               |   4 +-
 arch/powerpc/kvm/book3s_pr.c                       |  20 +-
 arch/powerpc/mm/numa.c                             |   5 -
 arch/powerpc/platforms/pseries/hotplug-cpu.c       |   2 +
 arch/s390/kernel/compat_linux.c                    |   8 +-
 arch/s390/kvm/kvm-s390.c                           |   1 +
 arch/sh/kernel/traps_32.c                          |   3 +-
 arch/sparc/crypto/crc32c_glue.c                    |   1 +
 arch/x86/crypto/crc32-pclmul_glue.c                |   1 +
 arch/x86/crypto/crc32c-intel_glue.c                |   1 +
 arch/x86/include/asm/apm.h                         |   6 +
 arch/x86/include/asm/cpufeature.h                  |  15 +-
 arch/x86/include/asm/efi.h                         |   8 +
 arch/x86/include/asm/intel-family.h                |  11 +-
 arch/x86/include/asm/kvm_host.h                    |   8 +-
 arch/x86/include/asm/nospec-branch.h               |  37 ++
 arch/x86/include/asm/pgtable.h                     |   4 +-
 arch/x86/include/asm/pgtable_types.h               |   5 +
 arch/x86/include/asm/vmx.h                         |   1 +
 arch/x86/include/uapi/asm/mce.h                    |   4 +
 arch/x86/include/uapi/asm/msr-index.h              |  12 +
 arch/x86/kernel/aperture_64.c                      |  46 +-
 arch/x86/kernel/cpu/bugs.c                         |  19 +-
 arch/x86/kernel/cpu/common.c                       |  75 ++-
 arch/x86/kernel/cpu/intel.c                        |  71 +++
 arch/x86/kernel/cpu/mcheck/mce.c                   |  26 +-
 arch/x86/kernel/cpu/microcode/core.c               |   2 +-
 arch/x86/kernel/cpu/microcode/core_early.c         |  29 +-
 arch/x86/kernel/entry_64.S                         |   2 +-
 arch/x86/kernel/traps.c                            |  27 +-
 arch/x86/kvm/cpuid.c                               |  24 +-
 arch/x86/kvm/cpuid.h                               |  31 ++
 arch/x86/kvm/svm.c                                 | 171 +++++-
 arch/x86/kvm/vmx.c                                 | 619 +++++++++++----------
 arch/x86/kvm/x86.c                                 | 111 ++--
 arch/x86/mm/tlb.c                                  |  19 +
 arch/x86/oprofile/nmi_int.c                        |   2 +-
 arch/x86/xen/mmu.c                                 |   2 +-
 arch/x86/xen/suspend.c                             |  24 +
 arch/x86/xen/xen-head.S                            |  15 +
 arch/xtensa/include/asm/futex.h                    |  23 +-
 crypto/af_alg.c                                    |   5 +
 crypto/ahash.c                                     |  33 +-
 crypto/algif_hash.c                                |  54 +-
 crypto/crc32.c                                     |   1 +
 crypto/crc32c_generic.c                            |   1 +
 crypto/cryptd.c                                    |   6 +-
 crypto/shash.c                                     |  25 +-
 drivers/ata/ahci.c                                 |  24 +-
 drivers/ata/libata-core.c                          |  21 +-
 drivers/ata/libata-eh.c                            |   3 +-
 drivers/ata/libata-scsi.c                          |   4 +-
 drivers/block/pktcdvd.c                            |   4 +-
 drivers/block/rbd.c                                |   7 +-
 drivers/cdrom/cdrom.c                              |   2 +-
 drivers/char/tpm/tpm-interface.c                   |   4 +
 drivers/char/tpm/tpm_i2c_infineon.c                |   5 +-
 drivers/char/tpm/tpm_i2c_nuvoton.c                 |   8 +-
 drivers/char/tpm/tpm_tis.c                         |   5 +-
 drivers/clocksource/fsl_ftm_timer.c                |   2 +-
 drivers/cpufreq/s3c24xx-cpufreq.c                  |   8 +-
 drivers/crypto/bfin_crc.c                          |   3 +-
 drivers/crypto/caam/ctrl.c                         |   8 +-
 drivers/crypto/s5p-sss.c                           |  12 +-
 drivers/devfreq/devfreq.c                          |   2 +-
 drivers/edac/octeon_edac-lmc.c                     |   1 +
 drivers/firmware/dmi_scan.c                        |  22 +-
 drivers/gpu/drm/drm_edid.c                         |   3 +
 drivers/gpu/drm/drm_probe_helper.c                 |  20 +
 drivers/gpu/drm/nouveau/nouveau_connector.c        |  18 +-
 drivers/gpu/drm/radeon/cik.c                       |  31 +-
 drivers/gpu/drm/radeon/radeon_connectors.c         | 105 ++--
 drivers/gpu/drm/radeon/radeon_device.c             |   4 +
 drivers/gpu/drm/radeon/radeon_gem.c                |   2 -
 drivers/gpu/drm/radeon/radeon_object.c             |   2 +
 drivers/gpu/drm/radeon/radeon_uvd.c                |   2 +-
 drivers/gpu/drm/radeon/si_dpm.c                    |   5 +
 drivers/gpu/drm/ttm/ttm_bo.c                       |   3 +-
 drivers/gpu/drm/udl/udl_fb.c                       |   9 +-
 drivers/hid/hid-core.c                             |   3 +
 drivers/hid/hid-ids.h                              |   4 +
 drivers/hid/hid-roccat-kovaplus.c                  |   2 +
 drivers/hid/usbhid/hid-quirks.c                    |   1 +
 drivers/iio/imu/adis_trigger.c                     |   7 +-
 drivers/iio/industrialio-buffer.c                  |   2 +-
 drivers/infiniband/core/cma.c                      |   5 +-
 drivers/infiniband/core/iwpm_util.c                |   1 +
 drivers/infiniband/core/ucma.c                     |  51 +-
 drivers/infiniband/hw/mlx4/main.c                  |  13 +-
 drivers/infiniband/hw/mlx5/cq.c                    |   7 +-
 drivers/infiniband/hw/mlx5/qp.c                    |   5 +-
 drivers/infiniband/hw/mlx5/srq.c                   |  15 +-
 drivers/infiniband/ulp/ipoib/ipoib_fs.c            |   2 -
 drivers/input/keyboard/matrix_keypad.c             |   4 +-
 drivers/input/touchscreen/edt-ft5x06.c             |  14 +-
 drivers/input/touchscreen/mms114.c                 |   2 +-
 drivers/md/bcache/super.c                          |  27 +-
 drivers/md/raid10.c                                |   6 +-
 drivers/media/pci/bt8xx/bt878.c                    |   3 +-
 drivers/media/platform/exynos4-is/fimc-isp.c       |  14 +-
 drivers/media/usb/cpia2/cpia2_v4l.c                |   4 +-
 drivers/media/usb/dvb-usb-v2/lmedm04.c             |  39 +-
 drivers/media/usb/dvb-usb/cxusb.c                  |   2 +
 drivers/media/usb/dvb-usb/dib0700_devices.c        |   1 +
 drivers/misc/lkdtm.c                               |   2 +-
 drivers/mmc/card/block.c                           |  21 +
 drivers/mmc/host/dw_mmc-exynos.c                   |   1 +
 drivers/mmc/host/dw_mmc.c                          |  68 ++-
 drivers/mmc/host/dw_mmc.h                          |   2 +
 drivers/mmc/host/sdhci-pci.c                       |  27 +
 drivers/mmc/host/sdhci.c                           |   7 +-
 drivers/mmc/host/sdhci.h                           |   1 +
 drivers/mtd/chips/jedec_probe.c                    |   2 +
 drivers/mtd/nand/nand_base.c                       |   5 +-
 drivers/mtd/ubi/vmt.c                              |  15 +-
 drivers/mtd/ubi/wl.c                               |   8 +-
 drivers/net/bonding/bond_main.c                    |  73 +--
 drivers/net/can/cc770/cc770.c                      | 100 ++--
 drivers/net/can/cc770/cc770.h                      |   2 +
 drivers/net/ethernet/broadcom/bcmsysport.c         |  33 +-
 drivers/net/ethernet/broadcom/bcmsysport.h         |   2 +-
 drivers/net/ethernet/intel/e1000e/ich8lan.c        |   2 +-
 drivers/net/ethernet/intel/e1000e/mac.c            |   2 +-
 drivers/net/ethernet/mellanox/mlx4/en_dcb_nl.c     |  23 +-
 drivers/net/ethernet/mellanox/mlx4/en_ethtool.c    |  27 +-
 drivers/net/ethernet/mellanox/mlx4/en_main.c       |   4 +-
 drivers/net/ethernet/mellanox/mlx4/mr.c            |  40 +-
 drivers/net/ethernet/mellanox/mlx4/qp.c            |   3 +
 drivers/net/slip/slip.c                            |   4 +-
 drivers/net/team/team.c                            |   4 +-
 drivers/net/tun.c                                  |   2 +-
 drivers/net/wireless/ath/ath9k/htc_drv_main.c      |   4 +
 drivers/net/wireless/brcm80211/brcmfmac/p2p.c      |  24 +-
 drivers/net/wireless/ti/wl1251/main.c              |   3 +-
 drivers/pci/quirks.c                               |   2 +
 drivers/pinctrl/core.c                             |  24 +-
 drivers/platform/x86/apple-gmux.c                  |  48 +-
 drivers/power/ab8500_charger.c                     |   6 +-
 drivers/s390/net/qeth_core.h                       |   5 +
 drivers/s390/net/qeth_core_main.c                  |  16 +-
 drivers/s390/net/qeth_l2_main.c                    |   2 +-
 drivers/s390/net/qeth_l3_main.c                    |   2 +-
 drivers/scsi/aacraid/aachba.c                      |  22 +-
 drivers/scsi/arm/fas216.c                          |   2 +-
 drivers/scsi/ibmvscsi/ibmvfc.h                     |   2 +-
 drivers/scsi/ipr.c                                 |   3 +-
 drivers/scsi/libsas/sas_ata.c                      |   4 +-
 drivers/scsi/libsas/sas_discover.c                 |  32 +-
 drivers/scsi/libsas/sas_expander.c                 |  11 +-
 drivers/scsi/libsas/sas_internal.h                 |   1 +
 drivers/scsi/libsas/sas_port.c                     |   3 +
 drivers/spi/spi-imx.c                              |  15 +-
 drivers/spi/spi-sun6i.c                            |   2 +-
 drivers/staging/android/ashmem.c                   |  32 +-
 drivers/staging/android/binder.c                   |  14 +-
 drivers/staging/iio/adc/ad7192.c                   |  29 +-
 drivers/staging/iio/adc/ad7192.h                   |   2 +-
 drivers/staging/iio/adc/ad7280a.c                  |   4 +-
 .../lustre/libcfs/linux/linux-crypto-adler.c       |   1 +
 drivers/staging/lustre/lustre/libcfs/tracefile.c   |   2 +-
 drivers/staging/rts5208/ms.c                       |   3 +-
 drivers/staging/usbip/stub_dev.c                   |   3 +
 drivers/staging/usbip/userspace/src/usbip_bind.c   |   9 +
 drivers/staging/usbip/userspace/src/usbip_list.c   |   9 +
 drivers/staging/usbip/vhci_hcd.c                   |   2 +
 drivers/tty/n_tty.c                                |   6 +
 drivers/tty/serial/8250/8250_pci.c                 |  11 +
 drivers/tty/serial/atmel_serial.c                  |   1 +
 drivers/tty/serial/sh-sci.c                        |   2 +
 drivers/tty/vt/vt.c                                |   8 +-
 drivers/usb/class/cdc-acm.c                        |   5 +-
 drivers/usb/core/message.c                         |   4 +
 drivers/usb/core/quirks.c                          |   6 +-
 drivers/usb/dwc3/gadget.c                          |   2 +
 drivers/usb/gadget/f_fs.c                          |   9 +-
 drivers/usb/host/ohci-q.c                          |  17 +-
 drivers/usb/host/xhci-pci.c                        |   3 +
 drivers/usb/host/xhci.c                            |   3 +
 drivers/usb/host/xhci.h                            |   1 +
 drivers/usb/misc/ldusb.c                           |   6 +
 drivers/usb/mon/mon_text.c                         | 124 +++--
 drivers/usb/serial/Kconfig                         |   3 +
 drivers/usb/serial/io_edgeport.c                   |   1 -
 drivers/usb/serial/option.c                        |   5 +
 drivers/usb/serial/pl2303.c                        |   1 +
 drivers/usb/serial/pl2303.h                        |   1 +
 drivers/usb/serial/usb-serial-simple.c             |  26 +-
 drivers/usb/storage/uas.c                          |  22 +-
 drivers/usb/storage/unusual_devs.h                 |   7 +
 drivers/vhost/net.c                                |   1 +
 drivers/video/console/dummycon.c                   |   1 -
 drivers/video/fbdev/atmel_lcdfb.c                  |  10 +-
 drivers/video/fbdev/sbuslib.c                      |   4 +-
 drivers/xen/events/events_base.c                   |   4 +-
 drivers/xen/manage.c                               |   9 +-
 fs/aio.c                                           | 134 +++--
 fs/btrfs/backref.c                                 |  11 +-
 fs/btrfs/inode.c                                   |  44 +-
 fs/btrfs/sysfs.c                                   |   6 +-
 fs/btrfs/transaction.c                             |  20 +-
 fs/btrfs/tree-log.c                                |  14 +-
 fs/btrfs/volumes.c                                 |  11 +-
 fs/cifs/cifsencrypt.c                              |   3 +-
 fs/cifs/cifssmb.c                                  |   4 +-
 fs/cifs/connect.c                                  |   4 +-
 fs/cifs/file.c                                     |  26 +-
 fs/cifs/misc.c                                     |  14 +-
 fs/cifs/smb2pdu.c                                  |   6 +-
 fs/dcache.c                                        |  11 +-
 fs/ext4/balloc.c                                   |  17 +-
 fs/ext4/ialloc.c                                   |   6 +
 fs/ext4/inode.c                                    |   6 +
 fs/ext4/super.c                                    |   1 +
 fs/f2fs/segment.c                                  |   5 +-
 fs/hugetlbfs/inode.c                               |  26 +-
 fs/jffs2/fs.c                                      |   1 -
 fs/kernfs/file.c                                   |   2 +-
 fs/namei.c                                         |   5 +-
 fs/ncpfs/ncplib_kernel.c                           |   4 +
 fs/nfs/direct.c                                    |   4 +-
 fs/nfs/idmap.c                                     |   6 +-
 fs/nfs/internal.h                                  |   1 -
 fs/nfs/nfs4sysctl.c                                |   2 +-
 fs/nfs/pagelist.c                                  |  26 +-
 fs/nfs/pnfs.c                                      |   6 +-
 fs/nfs/super.c                                     |   2 +
 fs/nfs/write.c                                     |   2 +
 fs/ocfs2/cluster/nodemanager.c                     |  63 ++-
 fs/pipe.c                                          | 198 ++++---
 include/crypto/hash.h                              |  34 +-
 include/crypto/internal/hash.h                     |   2 +
 include/drm/drm_crtc_helper.h                      |   1 +
 include/linux/crypto.h                             |   8 +
 include/linux/fs.h                                 |   4 +
 include/linux/libata.h                             |   1 +
 include/linux/mlx5/driver.h                        |   4 +-
 include/linux/mmc/sdhci.h                          |   1 +
 include/linux/nospec.h                             |   3 +-
 include/linux/pipe_fs_i.h                          |   4 +-
 include/linux/skbuff.h                             |  17 +
 include/linux/usb/quirks.h                         |   3 +
 include/linux/workqueue.h                          |   1 +
 include/net/ip.h                                   |  11 +-
 include/net/ip_fib.h                               |   1 +
 include/net/regulatory.h                           |   2 +-
 include/net/route.h                                |   3 +-
 include/net/sch_generic.h                          |   8 +
 include/net/sctp/sctp.h                            |   7 +-
 include/net/udplite.h                              |   1 +
 include/scsi/libsas.h                              |  33 +-
 include/scsi/scsi_transport_sas.h                  |   1 +
 include/uapi/linux/if_ether.h                      |   3 +
 include/uapi/linux/usb/audio.h                     |   4 +-
 include/xen/xen-ops.h                              |   1 +
 kernel/async.c                                     |  20 +-
 kernel/events/hw_breakpoint.c                      |  30 +-
 kernel/hrtimer.c                                   |   7 +-
 kernel/posix-timers.c                              |  15 +-
 kernel/relay.c                                     |   2 +-
 kernel/sysctl.c                                    |  33 +-
 kernel/trace/trace_kprobe.c                        |   4 +-
 kernel/trace/trace_probe.c                         |   8 +-
 kernel/trace/trace_probe.h                         |   2 +-
 kernel/workqueue.c                                 |  16 +
 mm/hugetlb.c                                       |   9 +
 mm/madvise.c                                       |   3 +-
 mm/memory.c                                        |   2 +-
 mm/mempolicy.c                                     |   3 +
 mm/vmscan.c                                        |  14 +-
 net/9p/trans_virtio.c                              |   3 +-
 net/batman-adv/bat_iv_ogm.c                        |  16 +-
 net/batman-adv/distributed-arp-table.c             |   2 +-
 net/batman-adv/fragmentation.c                     |   3 +-
 net/batman-adv/gateway_client.c                    |   3 +
 net/batman-adv/hard-interface.c                    |   9 +-
 net/batman-adv/multicast.c                         |   4 +-
 net/batman-adv/originator.c                        |   4 +-
 net/batman-adv/originator.h                        |   4 +-
 net/batman-adv/routing.c                           |  21 +-
 net/batman-adv/soft-interface.c                    |   8 +-
 net/batman-adv/types.h                             |   9 +-
 net/bluetooth/hidp/core.c                          |   3 +-
 net/bridge/br_sysfs_if.c                           |   3 +
 net/bridge/netfilter/ebt_among.c                   |  55 +-
 net/bridge/netfilter/ebtables.c                    |  17 +-
 net/core/dev.c                                     |  13 +-
 net/core/skbuff.c                                  |  11 +-
 net/dccp/proto.c                                   |   5 +
 net/decnet/af_decnet.c                             |  62 ++-
 net/ipv4/igmp.c                                    |   4 +
 net/ipv4/ip_sockglue.c                             |  21 +-
 net/ipv4/ip_tunnel.c                               |  30 +-
 net/ipv4/ip_vti.c                                  |   2 -
 net/ipv4/netfilter/ipt_CLUSTERIP.c                 |  24 +-
 net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c     |   6 +-
 net/ipv4/route.c                                   | 114 ++--
 net/ipv4/udp.c                                     |   5 +
 net/ipv4/xfrm4_policy.c                            |   1 +
 net/ipv6/ip6_checksum.c                            |   5 +
 net/ipv6/ip6_output.c                              |  13 +-
 net/ipv6/ipv6_sockglue.c                           |  27 +-
 net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c     |  18 +-
 net/ipv6/netfilter/nf_nat_l3proto_ipv6.c           |   4 +
 net/l2tp/l2tp_core.c                               | 202 +++----
 net/l2tp/l2tp_core.h                               |  26 +-
 net/l2tp/l2tp_ip.c                                 |  10 +-
 net/l2tp/l2tp_ip6.c                                |   8 +-
 net/l2tp/l2tp_ppp.c                                | 126 ++---
 net/mac80211/cfg.c                                 |   2 +-
 net/netfilter/nf_nat_proto_common.c                |   7 +-
 net/netfilter/xt_IDLETIMER.c                       |   9 +-
 net/netfilter/xt_LED.c                             |  12 +-
 net/netfilter/xt_RATEEST.c                         |  22 +-
 net/netlink/af_netlink.c                           |   3 +
 net/netlink/genetlink.c                            |  12 +-
 net/nfc/llcp_commands.c                            |   4 +
 net/nfc/netlink.c                                  |   3 +-
 net/sched/sch_netem.c                              |   6 +-
 net/sctp/sm_make_chunk.c                           |   8 +-
 net/xfrm/xfrm_user.c                               |  21 +-
 security/integrity/ima/ima_appraise.c              |   3 +-
 sound/core/oss/pcm_oss.c                           |   4 +-
 sound/core/pcm_native.c                            |   2 +-
 sound/core/seq/seq_clientmgr.c                     |  29 +-
 sound/core/seq/seq_fifo.c                          |   2 +-
 sound/core/seq/seq_memory.c                        |  14 +-
 sound/core/seq/seq_memory.h                        |   3 +-
 sound/core/seq/seq_prioq.c                         |  28 +-
 sound/core/seq/seq_prioq.h                         |   6 +-
 sound/core/seq/seq_queue.c                         |  28 +-
 sound/drivers/aloop.c                              |  17 +-
 sound/pci/hda/patch_realtek.c                      |  25 +-
 sound/soc/au1x/ac97c.c                             |   6 +-
 sound/soc/codecs/rt5651.c                          |   1 +
 sound/soc/nuc900/nuc900-ac97.c                     |   4 +-
 sound/usb/pcm.c                                    |   9 +
 sound/usb/quirks-table.h                           |  47 ++
 tools/perf/builtin-record.c                        |  13 +
 tools/perf/util/annotate.c                         |   8 +-
 tools/perf/util/evlist.c                           |  28 +
 tools/perf/util/evlist.h                           |   3 +
 tools/perf/util/session.c                          |   3 +-
 .../testing/selftests/rcutorture/bin/configinit.sh |   2 +-
 tools/testing/selftests/rcutorture/bin/kvm.sh      |   4 +-
 virt/kvm/kvm_main.c                                |   3 +-
 374 files changed, 3739 insertions(+), 2144 deletions(-)
Signature · 3 lines
Ben Hutchings
The most exhausting thing in life is being insincere.
                                                 - Anne Morrow Lindberg
#1 lore raw

PATCH 1/410 MIPS: Normalise code flow in the CpU exception handler

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: "Maciej W. Rozycki" <[email protected]>

commit 27e28e8ec47a5ce335ebf25d34ca356c80635908 upstream.

Changes applied to do_cpu' over time reduced the use of the SIGILL issued with force_sig' at the end to a single CU3 case only in the switch statement there. Move that `force_sig' call over to right where required then and toss out the pile of gotos now not needed to skip over the call, replacing them with regular breaks out of the switch.

Patchwork: https://patchwork.linux-mips.org/patch/9683/

---
 arch/mips/kernel/traps.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
arch/mips/kernel/traps.c +7 -8
@@ -1247,7 +1247,7 @@ asmlinkage void do_cpu(struct pt_regs *r
 		status = -1;
 
 		if (unlikely(compute_return_epc(regs) < 0))
-			goto out;
+			break;
 
 		if (get_isa16_mode(regs->cp0_epc)) {
 			unsigned short mmop[2] = { 0 };
@@ -1280,7 +1280,7 @@ asmlinkage void do_cpu(struct pt_regs *r
 			force_sig(status, current);
 		}
 
-		goto out;
+		break;
 
 	case 3:
 		/*
@@ -1296,8 +1296,10 @@ asmlinkage void do_cpu(struct pt_regs *r
 		 * erroneously too, so they are covered by this choice
 		 * as well.
 		 */
-		if (raw_cpu_has_fpu)
+		if (raw_cpu_has_fpu) {
+			force_sig(SIGILL, current);
 			break;
+		}
 		/* Fall through.  */
 
 	case 1:
@@ -1320,16 +1322,13 @@ asmlinkage void do_cpu(struct pt_regs *r
 		if (!process_fpemu_return(sig, fault_addr, fcr31) && !err)
 			mt_ase_fp_affinity();
 
-		goto out;
+		break;
 
 	case 2:
 		raw_notifier_call_chain(&cu2_chain, CU2_EXCEPTION, regs);
-		goto out;
+		break;
 	}
 
-	force_sig(SIGILL, current);
-
-out:
 	exception_exit(prev_state);
 }
 
#2 lore raw

PATCH 2/410 tun: allow positive return values on dev_get_valid_name() call

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Julien Gomes <[email protected]>

commit 5c25f65fd1e42685f7ccd80e0621829c105785d9 upstream.

If the name argument of dev_get_valid_name() contains "%d", it will try to assign it a unit number in __dev__alloc_name() and return either the unit number (>= 0) or an error code (< 0).
Considering positive values as error values prevent tun device creations relying this mechanism, therefor we should only consider negative values as errors here.

---
 drivers/net/tun.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/tun.c +1 -1
@@ -1648,7 +1648,7 @@ static int tun_set_iff(struct net *net,
 		if (!dev)
 			return -ENOMEM;
 		err = dev_get_valid_name(net, dev, name);
-		if (err)
+		if (err < 0)
 			goto err_free_dev;
 
 		dev_net_set(dev, net);
#3 lore raw

PATCH 3/410 x86, microcode: Fix accessing dis_ucode_ldr on 32-bit

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Borislav Petkov <[email protected]>

commit 85be07c32496dc264661308e4d9d4e9ccaff8072 upstream.

We should be accessing it through a pointer, like on the BSP.

Fixes 65cef1311d5d ("x86, microcode: Add a disable chicken bit")
---
 arch/x86/kernel/cpu/microcode/core_early.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/microcode/core_early.c +1 -1
@@ -124,7 +124,7 @@ void __init load_ucode_bsp(void)
 static bool check_loader_disabled_ap(void)
 {
 #ifdef CONFIG_X86_32
-	return __pa_nodebug(dis_ucode_ldr);
+	return *((bool *)__pa_nodebug(&dis_ucode_ldr));
 #else
 	return dis_ucode_ldr;
 #endif
#4 lore raw

PATCH 4/410 x86/microcode/AMD: Do not load when running on a hypervisor

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Borislav Petkov <[email protected]>

commit a15a753539eca8ba243d576f02e7ca9c4b7d7042 upstream.

Doing so is completely void of sense for multiple reasons so prevent it. Set dis_ucode_ldr to true and thus disable the microcode loader by default to address xen pv guests which execute the AP path but not the BSP path.

By having it turned off by default, the APs won't run into the loader either.

Also, check CPUID(1).ECX[31] which hypervisors set. Well almost, not the xen pv one. That one gets the aforementioned "fix".

Also, improve the detection method by caching the final decision whether to continue loading in dis_ucode_ldr and do it once on the BSP. The APs then simply test that value.

[bwh: Backported to 3.16:
- Early microcode loader is optional, so only set dis_ucode_ldr by default if it is enabled
- Adjust context, filename]

---

arch/x86/kernel/cpu/microcode/core.c +1 -1
@@ -97,7 +97,7 @@ MODULE_LICENSE("GPL");
 
 static struct microcode_ops	*microcode_ops;
 
-bool dis_ucode_ldr;
+bool dis_ucode_ldr = IS_ENABLED(CONFIG_MICROCODE_EARLY);
 module_param(dis_ucode_ldr, bool, 0);
 
 /*
arch/x86/kernel/cpu/microcode/core_early.c +19 -8
@@ -76,6 +76,8 @@ static int x86_family(void)
 
 static bool __init check_loader_disabled_bsp(void)
 {
+	u32 a, b, c, d;
+
 #ifdef CONFIG_X86_32
 	const char *cmdline = (const char *)__pa_nodebug(boot_command_line);
 	const char *opt	    = "dis_ucode_ldr";
@@ -88,8 +90,23 @@ static bool __init check_loader_disabled
 	bool *res = &dis_ucode_ldr;
 #endif
 
-	if (cmdline_find_option_bool(cmdline, option))
-		*res = true;
+	if (!have_cpuid_p())
+		return *res;
+
+	a = 1;
+	c = 0;
+	native_cpuid(&a, &b, &c, &d);
+
+	/*
+	 * CPUID(1).ECX[31]: reserved for hypervisor use. This is still not
+	 * completely accurate as xen pv guests don't see that CPUID bit set but
+	 * that's good enough as they don't land on the BSP path anyway.
+	 */
+	if (c & BIT(31))
+		return *res;
+
+	if (cmdline_find_option_bool(cmdline, option) <= 0)
+		*res = false;
 
 	return *res;
 }
@@ -101,9 +118,6 @@ void __init load_ucode_bsp(void)
 	if (check_loader_disabled_bsp())
 		return;
 
-	if (!have_cpuid_p())
-		return;
-
 	vendor = x86_vendor();
 	x86 = x86_family();
 
@@ -137,9 +151,6 @@ void load_ucode_ap(void)
 	if (check_loader_disabled_ap())
 		return;
 
-	if (!have_cpuid_p())
-		return;
-
 	vendor = x86_vendor();
 	x86 = x86_family();
 
#5 lore raw

PATCH 5/410 sctp: Fix mangled IPv4 addresses on a IPv6 listening socket

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Jason Gunthorpe <[email protected]>

commit 9302d7bb0c5cd46be5706859301f18c137b2439f upstream.

sctp_v4_map_v6 was subtly writing and reading from members of a union in a way the clobbered data it needed to read before it read it.

Zeroing the v6 flowinfo overwrites the v4 sin_addr with 0, meaning that every place that calls sctp_v4_map_v6 gets ::ffff:0.0.0.0 as the result.

Reorder things to guarantee correct behaviour no matter what the union layout is.

This impacts user space clients that open an IPv6 SCTP socket and receive IPv4 connections. Prior to 299ee user space would see a sockaddr with AF_INET and a correct address, after 299ee the sockaddr is AF_INET6, but the address is wrong.

Fixes 299ee123e198 (sctp: Fixup v4mapped behaviour to comply with Sock API)
---
 include/net/sctp/sctp.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
include/net/sctp/sctp.h +5 -2
@@ -582,11 +582,14 @@ static inline void sctp_v6_map_v4(union
 /* Map v4 address to v4-mapped v6 address */
 static inline void sctp_v4_map_v6(union sctp_addr *addr)
 {
+	__be16 port;
+
+	port = addr->v4.sin_port;
+	addr->v6.sin6_addr.s6_addr32[3] = addr->v4.sin_addr.s_addr;
+	addr->v6.sin6_port = port;
 	addr->v6.sin6_family = AF_INET6;
 	addr->v6.sin6_flowinfo = 0;
 	addr->v6.sin6_scope_id = 0;
-	addr->v6.sin6_port = addr->v4.sin_port;
-	addr->v6.sin6_addr.s6_addr32[3] = addr->v4.sin_addr.s_addr;
 	addr->v6.sin6_addr.s6_addr32[0] = 0;
 	addr->v6.sin6_addr.s6_addr32[1] = 0;
 	addr->v6.sin6_addr.s6_addr32[2] = htonl(0x0000ffff);
#6 lore raw

PATCH 6/410 Bluetooth: hidp_connection_add() unsafe use of l2cap_pi()

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Al Viro <[email protected]>

commit 51bda2bca53b265715ca1852528f38dc67429d9a upstream.

it's OK after we'd verified the sockets, but not before that.

---
 net/bluetooth/hidp/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/bluetooth/hidp/core.c +2 -1
@@ -1332,13 +1332,14 @@ int hidp_connection_add(struct hidp_conn
 {
 	struct hidp_session *session;
 	struct l2cap_conn *conn;
-	struct l2cap_chan *chan = l2cap_pi(ctrl_sock->sk)->chan;
+	struct l2cap_chan *chan;
 	int ret;
 
 	ret = hidp_verify_sockets(ctrl_sock, intr_sock);
 	if (ret)
 		return ret;
 
+	chan = l2cap_pi(ctrl_sock->sk)->chan;
 	conn = NULL;
 	l2cap_chan_lock(chan);
 	if (chan->conn) {
#7 lore raw

PATCH 7/410 media: dvb-usb-v2: lmedm04: Improve logic checking of warm start

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Malcolm Priestley <[email protected]>

commit 3d932ee27e852e4904647f15b64dedca51187ad7 upstream.

Warm start has no check as whether a genuine device has connected and proceeds to next execution path.

Check device should read 0x47 at offset of 2 on USB descriptor read and it is the amount requested of 6 bytes.

Fix for
kasan: CONFIG_KASAN_INLINE enabled
kasan: GPF could be caused by NULL-ptr deref or user memory access as

---
 drivers/media/usb/dvb-usb-v2/lmedm04.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)
drivers/media/usb/dvb-usb-v2/lmedm04.c +18 -8
@@ -434,18 +434,23 @@ static int lme2510_pid_filter(struct dvb
 
 static int lme2510_return_status(struct dvb_usb_device *d)
 {
-	int ret = 0;
+	int ret;
 	u8 *data;
 
-	data = kzalloc(10, GFP_KERNEL);
+	data = kzalloc(6, GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
-	ret |= usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0),
-			0x06, 0x80, 0x0302, 0x00, data, 0x0006, 200);
-	info("Firmware Status: %x (%x)", ret , data[2]);
+	ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0),
+			      0x06, 0x80, 0x0302, 0x00,
+			      data, 0x6, 200);
+	if (ret != 6)
+		ret = -EINVAL;
+	else
+		ret = data[2];
+
+	info("Firmware Status: %6ph", data);
 
-	ret = (ret < 0) ? -ENODEV : data[2];
 	kfree(data);
 	return ret;
 }
@@ -1228,6 +1233,7 @@ static int lme2510_get_adapter_count(str
 static int lme2510_identify_state(struct dvb_usb_device *d, const char **name)
 {
 	struct lme2510_state *st = d->priv;
+	int status;
 
 	usb_reset_configuration(d->udev);
 
@@ -1236,12 +1242,16 @@ static int lme2510_identify_state(struct
 
 	st->dvb_usb_lme2510_firmware = dvb_usb_lme2510_firmware;
 
-	if (lme2510_return_status(d) == 0x44) {
+	status = lme2510_return_status(d);
+	if (status == 0x44) {
 		*name = lme_firmware_switch(d, 0);
 		return COLD;
 	}
 
-	return 0;
+	if (status != 0x47)
+		return -EINVAL;
+
+	return WARM;
 }
 
 static int lme2510_get_stream_config(struct dvb_frontend *fe, u8 *ts_type,
#8 lore raw

PATCH 8/410 media: dvb-usb-v2: lmedm04: move ts2020 attach to dm04_lme2510_tuner

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Malcolm Priestley <[email protected]>

commit 7bf7a7116ed313c601307f7e585419369926ab05 upstream.

When the tuner was split from m88rs2000 the attach function is in wrong place.

Move to dm04_lme2510_tuner to trap errors on failure and removing a call to lme_coldreset.

Prevents driver starting up without any tuner connected.

Fixes to trap for ts2020 fail.
LME2510(C): FE Found M88RS2000
ts2020: probe of 0-0060 failed with error -11
...
LME2510(C): TUN Found RS2000 tuner
kasan: CONFIG_KASAN_INLINE enabled
kasan: GPF could be caused by NULL-ptr deref or user memory access

general protection fault: 0000 [#1] PREEMPT SMP KASAN
---
 drivers/media/usb/dvb-usb-v2/lmedm04.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/media/usb/dvb-usb-v2/lmedm04.c +6 -7
@@ -1115,8 +1115,6 @@ static int dm04_lme2510_frontend_attach(
 
 		if (adap->fe[0]) {
 			info("FE Found M88RS2000");
-			dvb_attach(ts2020_attach, adap->fe[0], &ts2020_config,
-					&d->i2c_adap);
 			st->i2c_tuner_gate_w = 5;
 			st->i2c_tuner_gate_r = 5;
 			st->i2c_tuner_addr = 0x60;
@@ -1179,17 +1177,18 @@ static int dm04_lme2510_tuner(struct dvb
 			ret = st->tuner_config;
 		break;
 	case TUNER_RS2000:
-		ret = st->tuner_config;
+		if (dvb_attach(ts2020_attach, adap->fe[0],
+			       &ts2020_config, &d->i2c_adap))
+			ret = st->tuner_config;
 		break;
 	default:
 		break;
 	}
 
-	if (ret)
+	if (ret) {
 		info("TUN Found %s tuner", tun_msg[ret]);
-	else {
-		info("TUN No tuner found --- resetting device");
-		lme_coldreset(d);
+	} else {
+		info("TUN No tuner found");
 		return -ENODEV;
 	}
 
#9 lore raw

PATCH 9/410 mm/madvise.c: fix madvise() infinite loop under special circumstances

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: chenjie <[email protected]>

commit 6ea8d958a2c95a1d514015d4e29ba21a8c0a1a91 upstream.

MADVISE_WILLNEED has always been a noop for DAX (formerly XIP) mappings. Unfortunately madvise_willneed() doesn't communicate this information properly to the generic madvise syscall implementation. The calling convention is quite subtle there. madvise_vma() is supposed to either return an error or update &prev otherwise the main loop will never advance to the next vma and it will keep looping for ever without a way to get out of the kernel.

It seems this has been broken since introduction. Nobody has noticed because nobody seems to be using MADVISE_WILLNEED on these DAX mappings.

[[email protected]: rewrite changelog]
Fixes fe77ba6f4f97 ("[PATCH] xip: madvice/fadvice: execute in place")
Cc Minchan Kim <[email protected]>
Cc zhangyi (F) <[email protected]>
Cc Miao Xie <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Shaohua Li <[email protected]>
Cc Andrea Arcangeli <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc David Rientjes <[email protected]>
Cc Anshuman Khandual <[email protected]>
Cc Rik van Riel <[email protected]>
Cc Carsten Otte <[email protected]>
Cc Dan Williams <[email protected]>
[bwh: Backported to 3.16: adjust context]

---

mm/madvise.c +1 -2
@@ -221,9 +221,9 @@ static long madvise_willneed(struct vm_a
 {
 	struct file *file = vma->vm_file;
 
+	*prev = vma;
 #ifdef CONFIG_SWAP
 	if (!file || mapping_cap_swap_backed(file->f_mapping)) {
-		*prev = vma;
 		if (!file)
 			force_swapin_readahead(vma, start, end);
 		else
@@ -241,7 +241,6 @@ static long madvise_willneed(struct vm_a
 		return 0;
 	}
 
-	*prev = vma;
 	start = ((start - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
 	if (end > vma->vm_end)
 		end = vma->vm_end;
#10 lore raw

PATCH 10/410 ocfs2: subsystem.su_mutex is required while accessing the item->ci_parent

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: alex chen <[email protected]>

commit 853bc26a7ea39e354b9f8889ae7ad1492ffa28d2 upstream.

The subsystem.su_mutex is required while accessing the item->ci_parent, otherwise, NULL pointer dereference to the item->ci_parent will be triggered in the following situation:

add node delete node
sys_write
vfs_write
configfs_write_file
o2nm_node_store

    o2nm_node_local_write
                             do_rmdir
                              vfs_rmdir
                               configfs_rmdir
                                mutex_lock(&subsys->su_mutex);
                                unlink_obj
                                 item->ci_group = NULL;
                                 item->ci_parent = NULL;
	 to_o2nm_cluster_from_node
	  node->nd_item.ci_parent->ci_parent
	  BUG since of NULL pointer dereference to nd_item.ci_parent

Moreover, the o2nm_cluster also should be protected by the subsystem.su_mutex.

---
 fs/ocfs2/cluster/nodemanager.c | 63 +++++++++++++++++++++++++++++-----
 1 file changed, 55 insertions(+), 8 deletions(-)
fs/ocfs2/cluster/nodemanager.c +55 -8
@@ -40,6 +40,9 @@ char *o2nm_fence_method_desc[O2NM_FENCE_
 		"panic",	/* O2NM_FENCE_PANIC */
 };
 
+static inline void o2nm_lock_subsystem(void);
+static inline void o2nm_unlock_subsystem(void);
+
 struct o2nm_node *o2nm_get_node_by_num(u8 node_num)
 {
 	struct o2nm_node *node = NULL;
@@ -181,7 +184,10 @@ static struct o2nm_cluster *to_o2nm_clus
 {
 	/* through the first node_set .parent
 	 * mycluster/nodes/mynode == o2nm_cluster->o2nm_node_group->o2nm_node */
-	return to_o2nm_cluster(node->nd_item.ci_parent->ci_parent);
+	if (node->nd_item.ci_parent)
+		return to_o2nm_cluster(node->nd_item.ci_parent->ci_parent);
+	else
+		return NULL;
 }
 
 enum {
@@ -194,7 +200,7 @@ enum {
 static ssize_t o2nm_node_num_write(struct o2nm_node *node, const char *page,
 				   size_t count)
 {
-	struct o2nm_cluster *cluster = to_o2nm_cluster_from_node(node);
+	struct o2nm_cluster *cluster;
 	unsigned long tmp;
 	char *p = (char *)page;
 
@@ -213,6 +219,13 @@ static ssize_t o2nm_node_num_write(struc
 	    !test_bit(O2NM_NODE_ATTR_PORT, &node->nd_set_attributes))
 		return -EINVAL; /* XXX */
 
+	o2nm_lock_subsystem();
+	cluster = to_o2nm_cluster_from_node(node);
+	if (!cluster) {
+		o2nm_unlock_subsystem();
+		return -EINVAL;
+	}
+
 	write_lock(&cluster->cl_nodes_lock);
 	if (cluster->cl_nodes[tmp])
 		p = NULL;
@@ -222,6 +235,8 @@ static ssize_t o2nm_node_num_write(struc
 		set_bit(tmp, cluster->cl_nodes_bitmap);
 	}
 	write_unlock(&cluster->cl_nodes_lock);
+	o2nm_unlock_subsystem();
+
 	if (p == NULL)
 		return -EEXIST;
 
@@ -261,7 +276,7 @@ static ssize_t o2nm_node_ipv4_address_wr
 					    const char *page,
 					    size_t count)
 {
-	struct o2nm_cluster *cluster = to_o2nm_cluster_from_node(node);
+	struct o2nm_cluster *cluster;
 	int ret, i;
 	struct rb_node **p, *parent;
 	unsigned int octets[4];
@@ -278,6 +293,13 @@ static ssize_t o2nm_node_ipv4_address_wr
 		be32_add_cpu(&ipv4_addr, octets[i] << (i * 8));
 	}
 
+	o2nm_lock_subsystem();
+	cluster = to_o2nm_cluster_from_node(node);
+	if (!cluster) {
+		o2nm_unlock_subsystem();
+		return -EINVAL;
+	}
+
 	ret = 0;
 	write_lock(&cluster->cl_nodes_lock);
 	if (o2nm_node_ip_tree_lookup(cluster, ipv4_addr, &p, &parent))
@@ -287,6 +309,8 @@ static ssize_t o2nm_node_ipv4_address_wr
 		rb_insert_color(&node->nd_ip_node, &cluster->cl_node_ip_tree);
 	}
 	write_unlock(&cluster->cl_nodes_lock);
+	o2nm_unlock_subsystem();
+
 	if (ret)
 		return ret;
 
@@ -303,7 +327,7 @@ static ssize_t o2nm_node_local_read(stru
 static ssize_t o2nm_node_local_write(struct o2nm_node *node, const char *page,
 				     size_t count)
 {
-	struct o2nm_cluster *cluster = to_o2nm_cluster_from_node(node);
+	struct o2nm_cluster *cluster;
 	unsigned long tmp;
 	char *p = (char *)page;
 	ssize_t ret;
@@ -321,17 +345,26 @@ static ssize_t o2nm_node_local_write(str
 	    !test_bit(O2NM_NODE_ATTR_PORT, &node->nd_set_attributes))
 		return -EINVAL; /* XXX */
 
+	o2nm_lock_subsystem();
+	cluster = to_o2nm_cluster_from_node(node);
+	if (!cluster) {
+		ret = -EINVAL;
+		goto out;
+	}
+
 	/* the only failure case is trying to set a new local node
 	 * when a different one is already set */
 	if (tmp && tmp == cluster->cl_has_local &&
-	    cluster->cl_local_node != node->nd_num)
-		return -EBUSY;
+	    cluster->cl_local_node != node->nd_num) {
+		ret = -EBUSY;
+		goto out;
+	}
 
 	/* bring up the rx thread if we're setting the new local node. */
 	if (tmp && !cluster->cl_has_local) {
 		ret = o2net_start_listening(node);
 		if (ret)
-			return ret;
+			goto out;
 	}
 
 	if (!tmp && cluster->cl_has_local &&
@@ -346,7 +379,11 @@ static ssize_t o2nm_node_local_write(str
 		cluster->cl_local_node = node->nd_num;
 	}
 
-	return count;
+	ret = count;
+
+out:
+	o2nm_unlock_subsystem();
+	return ret;
 }
 
 struct o2nm_node_attribute {
@@ -889,6 +926,16 @@ static struct o2nm_cluster_group o2nm_cl
 	},
 };
 
+static inline void o2nm_lock_subsystem(void)
+{
+	mutex_lock(&o2nm_cluster_group.cs_subsys.su_mutex);
+}
+
+static inline void o2nm_unlock_subsystem(void)
+{
+	mutex_unlock(&o2nm_cluster_group.cs_subsys.su_mutex);
+}
+
 int o2nm_depend_item(struct config_item *item)
 {
 	return configfs_depend_item(&o2nm_cluster_group.cs_subsys, item);
#11 lore raw

PATCH 11/410 scsi: libsas: remove the numbering for each event enum

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Jason Yan <[email protected]>

commit 0d78f969b10f27e0be34210d482a01e1ee92994c upstream.

Numbering for each event enum makes no sense. Remove the numbering so that we don't have to calculate the number by hand every time.

---
 include/scsi/libsas.h | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)
include/scsi/libsas.h +17 -17
@@ -67,31 +67,31 @@ enum ha_event {
 
 enum port_event {
 	PORTE_BYTES_DMAED     = 0U,
-	PORTE_BROADCAST_RCVD  = 1,
-	PORTE_LINK_RESET_ERR  = 2,
-	PORTE_TIMER_EVENT     = 3,
-	PORTE_HARD_RESET      = 4,
-	PORT_NUM_EVENTS       = 5,
+	PORTE_BROADCAST_RCVD,
+	PORTE_LINK_RESET_ERR,
+	PORTE_TIMER_EVENT,
+	PORTE_HARD_RESET,
+	PORT_NUM_EVENTS,
 };
 
 enum phy_event {
 	PHYE_LOSS_OF_SIGNAL   = 0U,
-	PHYE_OOB_DONE         = 1,
-	PHYE_OOB_ERROR        = 2,
-	PHYE_SPINUP_HOLD      = 3, /* hot plug SATA, no COMWAKE sent */
-	PHYE_RESUME_TIMEOUT   = 4,
-	PHY_NUM_EVENTS        = 5,
+	PHYE_OOB_DONE,
+	PHYE_OOB_ERROR,
+	PHYE_SPINUP_HOLD,             /* hot plug SATA, no COMWAKE sent */
+	PHYE_RESUME_TIMEOUT,
+	PHY_NUM_EVENTS,
 };
 
 enum discover_event {
 	DISCE_DISCOVER_DOMAIN   = 0U,
-	DISCE_REVALIDATE_DOMAIN = 1,
-	DISCE_PORT_GONE         = 2,
-	DISCE_PROBE		= 3,
-	DISCE_SUSPEND		= 4,
-	DISCE_RESUME		= 5,
-	DISCE_DESTRUCT		= 6,
-	DISC_NUM_EVENTS		= 7,
+	DISCE_REVALIDATE_DOMAIN,
+	DISCE_PORT_GONE,
+	DISCE_PROBE,
+	DISCE_SUSPEND,
+	DISCE_RESUME,
+	DISCE_DESTRUCT,
+	DISC_NUM_EVENTS,
 };
 
 /* ---------- Expander Devices ---------- */
#12 lore raw

PATCH 12/410 scsi: libsas: direct call probe and destruct

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Jason Yan <[email protected]>

commit 0558f33c06bb910e2879e355192227a8e8f0219d upstream.

In commit 87c8331fcf72 ("[SCSI] libsas: prevent domain rediscovery competing with ata error handling") introduced disco mutex to prevent rediscovery competing with ata error handling and put the whole revalidation in the mutex. But the rphy add/remove needs to wait for the error handling which also grabs the disco mutex. This may leads to dead lock.So the probe and destruct event were introduce to do the rphy add/remove asynchronously and out of the lock.

The asynchronously processed workers makes the whole discovery process not atomic, the other events may interrupt the process. For example, if a loss of signal event inserted before the probe event, the sas_deform_port() is called and the port will be deleted.

And sas_port_delete() may run before the destruct event, but the port-x:x is the top parent of end device or expander. This leads to a kernel WARNING such as:

[   82.042979] sysfs group 'power' not found for kobject 'phy-1:0:22'
[   82.042983] ------------[ cut here ]------------
[   82.042986] WARNING: CPU: 54 PID: 1714 at fs/sysfs/group.c:237
sysfs_remove_group+0x94/0xa0
[   82.043059] Call trace:
[   82.043082] [<ffff0000082e7624>] sysfs_remove_group+0x94/0xa0
[   82.043085] [<ffff00000864e320>] dpm_sysfs_remove+0x60/0x70
[   82.043086] [<ffff00000863ee10>] device_del+0x138/0x308
[   82.043089] [<ffff00000869a2d0>] sas_phy_delete+0x38/0x60
[   82.043091] [<ffff00000869a86c>] do_sas_phy_delete+0x6c/0x80
[   82.043093] [<ffff00000863dc20>] device_for_each_child+0x58/0xa0
[   82.043095] [<ffff000008696f80>] sas_remove_children+0x40/0x50
[   82.043100] [<ffff00000869d1bc>] sas_destruct_devices+0x64/0xa0
[   82.043102] [<ffff0000080e93bc>] process_one_work+0x1fc/0x4b0
[   82.043104] [<ffff0000080e96c0>] worker_thread+0x50/0x490
[   82.043105] [<ffff0000080f0364>] kthread+0xfc/0x128
[   82.043107] [<ffff0000080836c0>] ret_from_fork+0x10/0x50

Make probe and destruct a direct call in the disco and revalidate function, but put them outside the lock. The whole discovery or revalidate won't be interrupted by other events. And the DISCE_PROBE and DISCE_DESTRUCT event are deleted as a result of the direct call.

Introduce a new list to destruct the sas_port and put the port delete after the destruct. This makes sure the right order of destroying the sysfs kobject and fix the warning above.

In sas_ex_revalidate_domain() have a loop to find all broadcasted device, and sometimes we have a chance to find the same expander twice. Because the sas_port will be deleted at the end of the whole revalidate process, sas_port with the same name cannot be added before this. Otherwise the sysfs will complain of creating duplicate filename. Since the LLDD will send broadcast for every device change, we can only process one expander's revalidation.

[mkp: kbuild test robot warning]

CC John Garry <[email protected]>
CC Johannes Thumshirn <[email protected]>
CC Ewan Milne <[email protected]>
CC Christoph Hellwig <[email protected]>
CC Tomas Henzl <[email protected]>
CC Dan Williams <[email protected]>
[bwh: Backported to 4.9: adjust context]
---
 drivers/scsi/libsas/sas_ata.c      |  1 -
 drivers/scsi/libsas/sas_discover.c | 32 +++++++++++++++++-------------
 drivers/scsi/libsas/sas_expander.c |  8 +++-----
 drivers/scsi/libsas/sas_internal.h |  1 +
 drivers/scsi/libsas/sas_port.c     |  3 +++
 include/scsi/libsas.h              |  3 +--
 include/scsi/scsi_transport_sas.h  |  1 +
 7 files changed, 27 insertions(+), 22 deletions(-)
drivers/scsi/libsas/sas_ata.c +0 -1
@@ -782,7 +782,6 @@ int sas_discover_sata(struct domain_devi
 	if (res)
 		return res;
 
-	sas_discover_event(dev->port, DISCE_PROBE);
 	return 0;
 }
 
drivers/scsi/libsas/sas_discover.c +18 -14
@@ -212,13 +212,9 @@ void sas_notify_lldd_dev_gone(struct dom
 	}
 }
 
-static void sas_probe_devices(struct work_struct *work)
+static void sas_probe_devices(struct asd_sas_port *port)
 {
 	struct domain_device *dev, *n;
-	struct sas_discovery_event *ev = to_sas_discovery_event(work);
-	struct asd_sas_port *port = ev->port;
-
-	clear_bit(DISCE_PROBE, &port->disc.pending);
 
 	/* devices must be domain members before link recovery and probe */
 	list_for_each_entry(dev, &port->disco_list, disco_list_node) {
@@ -294,7 +290,6 @@ int sas_discover_end_dev(struct domain_d
 	res = sas_notify_lldd_dev_found(dev);
 	if (res)
 		return res;
-	sas_discover_event(dev->port, DISCE_PROBE);
 
 	return 0;
 }
@@ -353,13 +348,9 @@ static void sas_unregister_common_dev(st
 	sas_put_device(dev);
 }
 
-static void sas_destruct_devices(struct work_struct *work)
+void sas_destruct_devices(struct asd_sas_port *port)
 {
 	struct domain_device *dev, *n;
-	struct sas_discovery_event *ev = to_sas_discovery_event(work);
-	struct asd_sas_port *port = ev->port;
-
-	clear_bit(DISCE_DESTRUCT, &port->disc.pending);
 
 	list_for_each_entry_safe(dev, n, &port->destroy_list, disco_list_node) {
 		list_del_init(&dev->disco_list_node);
@@ -370,6 +361,16 @@ static void sas_destruct_devices(struct
 	}
 }
 
+static void sas_destruct_ports(struct asd_sas_port *port)
+{
+	struct sas_port *sas_port, *p;
+
+	list_for_each_entry_safe(sas_port, p, &port->sas_port_del_list, del_list) {
+		list_del_init(&sas_port->del_list);
+		sas_port_delete(sas_port);
+	}
+}
+
 void sas_unregister_dev(struct asd_sas_port *port, struct domain_device *dev)
 {
 	if (!test_bit(SAS_DEV_DESTROY, &dev->state) &&
@@ -384,7 +385,6 @@ void sas_unregister_dev(struct asd_sas_p
 	if (!test_and_set_bit(SAS_DEV_DESTROY, &dev->state)) {
 		sas_rphy_unlink(dev->rphy);
 		list_move_tail(&dev->disco_list_node, &port->destroy_list);
-		sas_discover_event(dev->port, DISCE_DESTRUCT);
 	}
 }
 
@@ -490,6 +490,8 @@ static void sas_discover_domain(struct w
 		port->port_dev = NULL;
 	}
 
+	sas_probe_devices(port);
+
 	SAS_DPRINTK("DONE DISCOVERY on port %d, pid:%d, result:%d\n", port->id,
 		    task_pid_nr(current), error);
 }
@@ -523,6 +525,10 @@ static void sas_revalidate_domain(struct
 		    port->id, task_pid_nr(current), res);
  out:
 	mutex_unlock(&ha->disco_mutex);
+
+	sas_destruct_devices(port);
+	sas_destruct_ports(port);
+	sas_probe_devices(port);
 }
 
 /* ---------- Events ---------- */
@@ -578,10 +584,8 @@ void sas_init_disc(struct sas_discovery
 	static const work_func_t sas_event_fns[DISC_NUM_EVENTS] = {
 		[DISCE_DISCOVER_DOMAIN] = sas_discover_domain,
 		[DISCE_REVALIDATE_DOMAIN] = sas_revalidate_domain,
-		[DISCE_PROBE] = sas_probe_devices,
 		[DISCE_SUSPEND] = sas_suspend_devices,
 		[DISCE_RESUME] = sas_resume_devices,
-		[DISCE_DESTRUCT] = sas_destruct_devices,
 	};
 
 	disc->pending = 0;
drivers/scsi/libsas/sas_expander.c +3 -5
@@ -1903,7 +1903,8 @@ static void sas_unregister_devs_sas_addr
 		sas_port_delete_phy(phy->port, phy->phy);
 		sas_device_set_phy(found, phy->port);
 		if (phy->port->num_phys == 0)
-			sas_port_delete(phy->port);
+			list_add_tail(&phy->port->del_list,
+				&parent->port->sas_port_del_list);
 		phy->port = NULL;
 	}
 }
@@ -2111,7 +2112,7 @@ int sas_ex_revalidate_domain(struct doma
 	struct domain_device *dev = NULL;
 
 	res = sas_find_bcast_dev(port_dev, &dev);
-	while (res == 0 && dev) {
+	if (res == 0 && dev) {
 		struct expander_device *ex = &dev->ex_dev;
 		int i = 0, phy_id;
 
@@ -2123,9 +2124,6 @@ int sas_ex_revalidate_domain(struct doma
 			res = sas_rediscover(dev, phy_id);
 			i = phy_id + 1;
 		} while (i < ex->num_phys);
-
-		dev = NULL;
-		res = sas_find_bcast_dev(port_dev, &dev);
 	}
 	return res;
 }
drivers/scsi/libsas/sas_internal.h +1 -0
@@ -100,6 +100,7 @@ int sas_try_ata_reset(struct asd_sas_phy
 void sas_hae_reset(struct work_struct *work);
 
 void sas_free_device(struct kref *kref);
+void sas_destruct_devices(struct asd_sas_port *port);
 
 #ifdef CONFIG_SCSI_SAS_HOST_SMP
 extern int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
drivers/scsi/libsas/sas_port.c +3 -0
@@ -66,6 +66,7 @@ static void sas_resume_port(struct asd_s
 		rc = sas_notify_lldd_dev_found(dev);
 		if (rc) {
 			sas_unregister_dev(port, dev);
+			sas_destruct_devices(port);
 			continue;
 		}
 
@@ -219,6 +220,7 @@ void sas_deform_port(struct asd_sas_phy
 
 	if (port->num_phys == 1) {
 		sas_unregister_domain_devices(port, gone);
+		sas_destruct_devices(port);
 		sas_port_delete(port->port);
 		port->port = NULL;
 	} else {
@@ -323,6 +325,7 @@ static void sas_init_port(struct asd_sas
 	INIT_LIST_HEAD(&port->dev_list);
 	INIT_LIST_HEAD(&port->disco_list);
 	INIT_LIST_HEAD(&port->destroy_list);
+	INIT_LIST_HEAD(&port->sas_port_del_list);
 	spin_lock_init(&port->phy_list_lock);
 	INIT_LIST_HEAD(&port->phy_list);
 	port->ha = sas_ha;
include/scsi/libsas.h +1 -2
@@ -87,10 +87,8 @@ enum discover_event {
 	DISCE_DISCOVER_DOMAIN   = 0U,
 	DISCE_REVALIDATE_DOMAIN,
 	DISCE_PORT_GONE,
-	DISCE_PROBE,
 	DISCE_SUSPEND,
 	DISCE_RESUME,
-	DISCE_DESTRUCT,
 	DISC_NUM_EVENTS,
 };
 
@@ -274,6 +272,7 @@ struct asd_sas_port {
 	struct list_head dev_list;
 	struct list_head disco_list;
 	struct list_head destroy_list;
+	struct list_head sas_port_del_list;
 	enum   sas_linkrate linkrate;
 
 	struct sas_work work;
include/scsi/scsi_transport_sas.h +1 -0
@@ -145,6 +145,7 @@ struct sas_port {
 
 	struct mutex		phy_list_mutex;
 	struct list_head	phy_list;
+	struct list_head	del_list; /* libsas only */
 };
 
 #define dev_to_sas_port(d) \

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#15 lore raw

Re: [PATCH 3.16 012/410] scsi: libsas: direct call probe and destruct

Quoted 16 lines · Ben Hutchings
Quoted 15 lines · John Garry
Quoted 4 lines · Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

Hi Ben,

I noticed that you are looking to backport this patch to 3.16

I am wondering why you are taking this libsas patch (and a couple other libsas patches) in isolation, when these patches were part of a series to fix libsas hotplug issues? I'm not sure if cherry-picking certain patches is ok.

Quoted 7 lines
Quoted 1 line

Maybe Jason (cc'ed) can comment further.

This one apparently fixed a security issue (CVE-2017-18232), though I'm certainly not convinced it's a particularly serious one.

But please send objections to the list, not just privately.

Hi Ben,

This patch is in the series below. I recommend to backport them together. If you really want to do this, I'm happy to help you to backport them.

1689c9367bfa scsi: libsas: notify event PORTE_BROADCAST_RCVD in sas_enable_revalidation() 0558f33c06bb scsi: libsas: direct call probe and destruct
517e5153d242 scsi: libsas: use flush_workqueue to process disco events synchronously 93bdbd06b164 scsi: libsas: Use new workqueue to run sas event and disco event 8eea9dd84e45 scsi: libsas: make the event threshold configurable f12486e06ae8 scsi: libsas: shut down the PHY if events reached the threshold 1c393b970e0f scsi: libsas: Use dynamic alloced work to avoid sas event lost

Quoted 294 lines

Ben.

Quoted 292 lines

Thanks,
John

Quoted 287 lines

From: Jason Yan <[email protected]>

commit 0558f33c06bb910e2879e355192227a8e8f0219d upstream.

In commit 87c8331fcf72 ("[SCSI] libsas: prevent domain rediscovery competing with ata error handling") introduced disco mutex to prevent rediscovery competing with ata error handling and put the whole revalidation in the mutex. But the rphy add/remove needs to wait for the error handling which also grabs the disco mutex. This may leads to dead lock.So the probe and destruct event were introduce to do the rphy add/remove asynchronously and out of the lock.

The asynchronously processed workers makes the whole discovery process not atomic, the other events may interrupt the process. For example, if a loss of signal event inserted before the probe event, the sas_deform_port() is called and the port will be deleted.

And sas_port_delete() may run before the destruct event, but the port-x:x is the top parent of end device or expander. This leads to a kernel WARNING such as:

[   82.042979] sysfs group 'power' not found for kobject 'phy-1:0:22'
[   82.042983] ------------[ cut here ]------------
[   82.042986] WARNING: CPU: 54 PID: 1714 at fs/sysfs/group.c:237
sysfs_remove_group+0x94/0xa0
[   82.043059] Call trace:
[   82.043082] [<ffff0000082e7624>] sysfs_remove_group+0x94/0xa0
[   82.043085] [<ffff00000864e320>] dpm_sysfs_remove+0x60/0x70
[   82.043086] [<ffff00000863ee10>] device_del+0x138/0x308
[   82.043089] [<ffff00000869a2d0>] sas_phy_delete+0x38/0x60
[   82.043091] [<ffff00000869a86c>] do_sas_phy_delete+0x6c/0x80
[   82.043093] [<ffff00000863dc20>] device_for_each_child+0x58/0xa0
[   82.043095] [<ffff000008696f80>] sas_remove_children+0x40/0x50
[   82.043100] [<ffff00000869d1bc>] sas_destruct_devices+0x64/0xa0
[   82.043102] [<ffff0000080e93bc>] process_one_work+0x1fc/0x4b0
[   82.043104] [<ffff0000080e96c0>] worker_thread+0x50/0x490
[   82.043105] [<ffff0000080f0364>] kthread+0xfc/0x128
[   82.043107] [<ffff0000080836c0>] ret_from_fork+0x10/0x50

Make probe and destruct a direct call in the disco and revalidate function, but put them outside the lock. The whole discovery or revalidate won't be interrupted by other events. And the DISCE_PROBE and DISCE_DESTRUCT event are deleted as a result of the direct call.

Introduce a new list to destruct the sas_port and put the port delete after the destruct. This makes sure the right order of destroying the sysfs kobject and fix the warning above.

In sas_ex_revalidate_domain() have a loop to find all broadcasted device, and sometimes we have a chance to find the same expander twice. Because the sas_port will be deleted at the end of the whole revalidate process, sas_port with the same name cannot be added before this. Otherwise the sysfs will complain of creating duplicate filename. Since the LLDD will send broadcast for every device change, we can only process one expander's revalidation.

[mkp: kbuild test robot warning]

CC John Garry <[email protected]>
CC Johannes Thumshirn <[email protected]>
CC Ewan Milne <[email protected]>
CC Christoph Hellwig <[email protected]>
CC Tomas Henzl <[email protected]>
CC Dan Williams <[email protected]>
[bwh: Backported to 4.9: adjust context]
---
  drivers/scsi/libsas/sas_ata.c      |  1 -
  drivers/scsi/libsas/sas_discover.c | 32 +++++++++++++++++-------------
  drivers/scsi/libsas/sas_expander.c |  8 +++-----
  drivers/scsi/libsas/sas_internal.h |  1 +
  drivers/scsi/libsas/sas_port.c     |  3 +++
  include/scsi/libsas.h              |  3 +--
  include/scsi/scsi_transport_sas.h  |  1 +
  7 files changed, 27 insertions(+), 22 deletions(-)
drivers/scsi/libsas/sas_ata.c +0 -1
@@ -782,7 +782,6 @@ int sas_discover_sata(struct domain_devi
  	if (res)
  		return res;
 
-	sas_discover_event(dev->port, DISCE_PROBE);
  	return 0;
  }
 
drivers/scsi/libsas/sas_discover.c +18 -14
@@ -212,13 +212,9 @@ void sas_notify_lldd_dev_gone(struct dom
  	}
  }
 
-static void sas_probe_devices(struct work_struct *work)
+static void sas_probe_devices(struct asd_sas_port *port)
  {
  	struct domain_device *dev, *n;
-	struct sas_discovery_event *ev = to_sas_discovery_event(work);
-	struct asd_sas_port *port = ev->port;
-
-	clear_bit(DISCE_PROBE, &port->disc.pending);
 
  	/* devices must be domain members before link recovery and probe */
  	list_for_each_entry(dev, &port->disco_list, disco_list_node) {
@@ -294,7 +290,6 @@ int sas_discover_end_dev(struct domain_d
  	res = sas_notify_lldd_dev_found(dev);
  	if (res)
  		return res;
-	sas_discover_event(dev->port, DISCE_PROBE);
 
  	return 0;
  }
@@ -353,13 +348,9 @@ static void sas_unregister_common_dev(st
  	sas_put_device(dev);
  }
 
-static void sas_destruct_devices(struct work_struct *work)
+void sas_destruct_devices(struct asd_sas_port *port)
  {
  	struct domain_device *dev, *n;
-	struct sas_discovery_event *ev = to_sas_discovery_event(work);
-	struct asd_sas_port *port = ev->port;
-
-	clear_bit(DISCE_DESTRUCT, &port->disc.pending);
 
  	list_for_each_entry_safe(dev, n, &port->destroy_list, disco_list_node) {
  		list_del_init(&dev->disco_list_node);
@@ -370,6 +361,16 @@ static void sas_destruct_devices(struct
  	}
  }
 
+static void sas_destruct_ports(struct asd_sas_port *port)
+{
+	struct sas_port *sas_port, *p;
+
+	list_for_each_entry_safe(sas_port, p, &port->sas_port_del_list, del_list) {
+		list_del_init(&sas_port->del_list);
+		sas_port_delete(sas_port);
+	}
+}
+
  void sas_unregister_dev(struct asd_sas_port *port, struct domain_device *dev)
  {
  	if (!test_bit(SAS_DEV_DESTROY, &dev->state) &&
@@ -384,7 +385,6 @@ void sas_unregister_dev(struct asd_sas_p
  	if (!test_and_set_bit(SAS_DEV_DESTROY, &dev->state)) {
  		sas_rphy_unlink(dev->rphy);
  		list_move_tail(&dev->disco_list_node, &port->destroy_list);
-		sas_discover_event(dev->port, DISCE_DESTRUCT);
  	}
  }
 
@@ -490,6 +490,8 @@ static void sas_discover_domain(struct w
  		port->port_dev = NULL;
  	}
 
+	sas_probe_devices(port);
+
  	SAS_DPRINTK("DONE DISCOVERY on port %d, pid:%d, result:%d\n", port->id,
  		    task_pid_nr(current), error);
  }
@@ -523,6 +525,10 @@ static void sas_revalidate_domain(struct
  		    port->id, task_pid_nr(current), res);
   out:
  	mutex_unlock(&ha->disco_mutex);
+
+	sas_destruct_devices(port);
+	sas_destruct_ports(port);
+	sas_probe_devices(port);
  }
 
  /* ---------- Events ---------- */
@@ -578,10 +584,8 @@ void sas_init_disc(struct sas_discovery
  	static const work_func_t sas_event_fns[DISC_NUM_EVENTS] = {
  		[DISCE_DISCOVER_DOMAIN] = sas_discover_domain,
  		[DISCE_REVALIDATE_DOMAIN] = sas_revalidate_domain,
-		[DISCE_PROBE] = sas_probe_devices,
  		[DISCE_SUSPEND] = sas_suspend_devices,
  		[DISCE_RESUME] = sas_resume_devices,
-		[DISCE_DESTRUCT] = sas_destruct_devices,
  	};
 
  	disc->pending = 0;
drivers/scsi/libsas/sas_expander.c +3 -5
@@ -1903,7 +1903,8 @@ static void sas_unregister_devs_sas_addr
  		sas_port_delete_phy(phy->port, phy->phy);
  		sas_device_set_phy(found, phy->port);
  		if (phy->port->num_phys == 0)
-			sas_port_delete(phy->port);
+			list_add_tail(&phy->port->del_list,
+				&parent->port->sas_port_del_list);
  		phy->port = NULL;
  	}
  }
@@ -2111,7 +2112,7 @@ int sas_ex_revalidate_domain(struct doma
  	struct domain_device *dev = NULL;
 
  	res = sas_find_bcast_dev(port_dev, &dev);
-	while (res == 0 && dev) {
+	if (res == 0 && dev) {
  		struct expander_device *ex = &dev->ex_dev;
  		int i = 0, phy_id;
 
@@ -2123,9 +2124,6 @@ int sas_ex_revalidate_domain(struct doma
  			res = sas_rediscover(dev, phy_id);
  			i = phy_id + 1;
  		} while (i < ex->num_phys);
-
-		dev = NULL;
-		res = sas_find_bcast_dev(port_dev, &dev);
  	}
  	return res;
  }
drivers/scsi/libsas/sas_internal.h +1 -0
@@ -100,6 +100,7 @@ int sas_try_ata_reset(struct asd_sas_phy
  void sas_hae_reset(struct work_struct *work);
 
  void sas_free_device(struct kref *kref);
+void sas_destruct_devices(struct asd_sas_port *port);
 
  #ifdef CONFIG_SCSI_SAS_HOST_SMP
  extern int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
drivers/scsi/libsas/sas_port.c +3 -0
@@ -66,6 +66,7 @@ static void sas_resume_port(struct asd_s
  		rc = sas_notify_lldd_dev_found(dev);
  		if (rc) {
  			sas_unregister_dev(port, dev);
+			sas_destruct_devices(port);
  			continue;
  		}
 
@@ -219,6 +220,7 @@ void sas_deform_port(struct asd_sas_phy
 
  	if (port->num_phys == 1) {
  		sas_unregister_domain_devices(port, gone);
+		sas_destruct_devices(port);
  		sas_port_delete(port->port);
  		port->port = NULL;
  	} else {
@@ -323,6 +325,7 @@ static void sas_init_port(struct asd_sas
  	INIT_LIST_HEAD(&port->dev_list);
  	INIT_LIST_HEAD(&port->disco_list);
  	INIT_LIST_HEAD(&port->destroy_list);
+	INIT_LIST_HEAD(&port->sas_port_del_list);
  	spin_lock_init(&port->phy_list_lock);
  	INIT_LIST_HEAD(&port->phy_list);
  	port->ha = sas_ha;
include/scsi/libsas.h +1 -2
@@ -87,10 +87,8 @@ enum discover_event {
  	DISCE_DISCOVER_DOMAIN   = 0U,
  	DISCE_REVALIDATE_DOMAIN,
  	DISCE_PORT_GONE,
-	DISCE_PROBE,
  	DISCE_SUSPEND,
  	DISCE_RESUME,
-	DISCE_DESTRUCT,
  	DISC_NUM_EVENTS,
  };
 
@@ -274,6 +272,7 @@ struct asd_sas_port {
  	struct list_head dev_list;
  	struct list_head disco_list;
  	struct list_head destroy_list;
+	struct list_head sas_port_del_list;
  	enum   sas_linkrate linkrate;
 
  	struct sas_work work;
include/scsi/scsi_transport_sas.h +1 -0
@@ -145,6 +145,7 @@ struct sas_port {
 
  	struct mutex		phy_list_mutex;
  	struct list_head	phy_list;
+	struct list_head	del_list; /* libsas only */
  };
 
  #define dev_to_sas_port(d) \

.

#16 lore raw

Re: [PATCH 3.16 012/410] scsi: libsas: direct call probe and destruct

Quoted 31 lines · Jason Yan
Quoted 16 lines · Ben Hutchings
Quoted 15 lines · John Garry
Quoted 4 lines · Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

Hi Ben,

I noticed that you are looking to backport this patch to 3.16

I am wondering why you are taking this libsas patch (and a couple other libsas patches) in isolation, when these patches were part of a series to fix libsas hotplug issues? I'm not sure if cherry-picking certain patches is ok.

Quoted 7 lines
Quoted 1 line

Maybe Jason (cc'ed) can comment further.

This one apparently fixed a security issue (CVE-2017-18232), though I'm certainly not convinced it's a particularly serious one.

But please send objections to the list, not just privately.

Hi Ben,

This patch is in the series below. I recommend to backport them together. If you really want to do this, I'm happy to help you to backport them.

Quoted 10 lines

1689c9367bfa scsi: libsas: notify event PORTE_BROADCAST_RCVD in sas_enable_revalidation()
0558f33c06bb scsi: libsas: direct call probe and destruct 517e5153d242 scsi: libsas: use flush_workqueue to process disco events synchronously
93bdbd06b164 scsi: libsas: Use new workqueue to run sas event and disco event
8eea9dd84e45 scsi: libsas: make the event threshold configurable f12486e06ae8 scsi: libsas: shut down the PHY if events reached the threshold 1c393b970e0f scsi: libsas: Use dynamic alloced work to avoid sas event lost

Thank you. I'll drop this single patch for now.

I'll leave it you and the other libsas developers to decide if it is sensible to backport this series to 3.16 (and other stable branches).

Ben.

Quoted 296 lines
Quoted 294 lines

Ben.

Quoted 292 lines

Thanks,
John

Quoted 287 lines

From: Jason Yan <[email protected]>

commit 0558f33c06bb910e2879e355192227a8e8f0219d upstream.

In commit 87c8331fcf72 ("[SCSI] libsas: prevent domain rediscovery competing with ata error handling") introduced disco mutex to prevent rediscovery competing with ata error handling and put the whole revalidation in the mutex. But the rphy add/remove needs to wait for the error handling which also grabs the disco mutex. This may leads to dead lock.So the probe and destruct event were introduce to do the rphy add/remove asynchronously and out of the lock.

The asynchronously processed workers makes the whole discovery process not atomic, the other events may interrupt the process. For example, if a loss of signal event inserted before the probe event, the sas_deform_port() is called and the port will be deleted.

And sas_port_delete() may run before the destruct event, but the port-x:x is the top parent of end device or expander. This leads to a kernel WARNING such as:

[   82.042979] sysfs group 'power' not found for kobject 'phy-1:0:22'
[   82.042983] ------------[ cut here ]------------
[   82.042986] WARNING: CPU: 54 PID: 1714 at fs/sysfs/group.c:237
sysfs_remove_group+0x94/0xa0
[   82.043059] Call trace:
[   82.043082] [<ffff0000082e7624>] sysfs_remove_group+0x94/0xa0
[   82.043085] [<ffff00000864e320>] dpm_sysfs_remove+0x60/0x70
[   82.043086] [<ffff00000863ee10>] device_del+0x138/0x308
[   82.043089] [<ffff00000869a2d0>] sas_phy_delete+0x38/0x60
[   82.043091] [<ffff00000869a86c>] do_sas_phy_delete+0x6c/0x80
[   82.043093] [<ffff00000863dc20>] device_for_each_child+0x58/0xa0
[   82.043095] [<ffff000008696f80>] sas_remove_children+0x40/0x50
[   82.043100] [<ffff00000869d1bc>] sas_destruct_devices+0x64/0xa0
[   82.043102] [<ffff0000080e93bc>] process_one_work+0x1fc/0x4b0
[   82.043104] [<ffff0000080e96c0>] worker_thread+0x50/0x490
[   82.043105] [<ffff0000080f0364>] kthread+0xfc/0x128
[   82.043107] [<ffff0000080836c0>] ret_from_fork+0x10/0x50

Make probe and destruct a direct call in the disco and revalidate function, but put them outside the lock. The whole discovery or revalidate won't be interrupted by other events. And the DISCE_PROBE and DISCE_DESTRUCT event are deleted as a result of the direct call.

Introduce a new list to destruct the sas_port and put the port delete after the destruct. This makes sure the right order of destroying the sysfs kobject and fix the warning above.

In sas_ex_revalidate_domain() have a loop to find all broadcasted device, and sometimes we have a chance to find the same expander twice. Because the sas_port will be deleted at the end of the whole revalidate process, sas_port with the same name cannot be added before this. Otherwise the sysfs will complain of creating duplicate filename. Since the LLDD will send broadcast for every device change, we can only process one expander's revalidation.

[mkp: kbuild test robot warning]

CC John Garry <[email protected]>
CC Johannes Thumshirn <[email protected]>
CC Ewan Milne <[email protected]>
CC Christoph Hellwig <[email protected]>
CC Tomas Henzl <[email protected]>
CC Dan Williams <[email protected]>
[bwh: Backported to 4.9: adjust context]
---
  drivers/scsi/libsas/sas_ata.c      |  1 -
  drivers/scsi/libsas/sas_discover.c | 32 +++++++++++++++++-------------
  drivers/scsi/libsas/sas_expander.c |  8 +++-----
  drivers/scsi/libsas/sas_internal.h |  1 +
  drivers/scsi/libsas/sas_port.c     |  3 +++
  include/scsi/libsas.h              |  3 +--
  include/scsi/scsi_transport_sas.h  |  1 +
  7 files changed, 27 insertions(+), 22 deletions(-)
drivers/scsi/libsas/sas_ata.c +0 -1
@@ -782,7 +782,6 @@ int sas_discover_sata(struct domain_devi
  	if (res)
  		return res;
 
-	sas_discover_event(dev->port, DISCE_PROBE);
  	return 0;
  }
 
drivers/scsi/libsas/sas_discover.c +18 -14
@@ -212,13 +212,9 @@ void sas_notify_lldd_dev_gone(struct dom
  	}
  }
 
-static void sas_probe_devices(struct work_struct *work)
+static void sas_probe_devices(struct asd_sas_port *port)
  {
  	struct domain_device *dev, *n;
-	struct sas_discovery_event *ev = to_sas_discovery_event(work);
-	struct asd_sas_port *port = ev->port;
-
-	clear_bit(DISCE_PROBE, &port->disc.pending);
 
  	/* devices must be domain members before link recovery and probe */
  	list_for_each_entry(dev, &port->disco_list, disco_list_node) {
@@ -294,7 +290,6 @@ int sas_discover_end_dev(struct domain_d
  	res = sas_notify_lldd_dev_found(dev);
  	if (res)
  		return res;
-	sas_discover_event(dev->port, DISCE_PROBE);
 
  	return 0;
  }
@@ -353,13 +348,9 @@ static void sas_unregister_common_dev(st
  	sas_put_device(dev);
  }
 
-static void sas_destruct_devices(struct work_struct *work)
+void sas_destruct_devices(struct asd_sas_port *port)
  {
  	struct domain_device *dev, *n;
-	struct sas_discovery_event *ev = to_sas_discovery_event(work);
-	struct asd_sas_port *port = ev->port;
-
-	clear_bit(DISCE_DESTRUCT, &port->disc.pending);
 
  	list_for_each_entry_safe(dev, n, &port->destroy_list, disco_list_node) {
  		list_del_init(&dev->disco_list_node);
@@ -370,6 +361,16 @@ static void sas_destruct_devices(struct
  	}
  }
 
+static void sas_destruct_ports(struct asd_sas_port *port)
+{
+	struct sas_port *sas_port, *p;
+
+	list_for_each_entry_safe(sas_port, p, &port->sas_port_del_list, del_list) {
+		list_del_init(&sas_port->del_list);
+		sas_port_delete(sas_port);
+	}
+}
+
  void sas_unregister_dev(struct asd_sas_port *port, struct domain_device *dev)
  {
  	if (!test_bit(SAS_DEV_DESTROY, &dev->state) &&
@@ -384,7 +385,6 @@ void sas_unregister_dev(struct asd_sas_p
  	if (!test_and_set_bit(SAS_DEV_DESTROY, &dev->state)) {
  		sas_rphy_unlink(dev->rphy);
  		list_move_tail(&dev->disco_list_node, &port->destroy_list);
-		sas_discover_event(dev->port, DISCE_DESTRUCT);
  	}
  }
 
@@ -490,6 +490,8 @@ static void sas_discover_domain(struct w
  		port->port_dev = NULL;
  	}
 
+	sas_probe_devices(port);
+
  	SAS_DPRINTK("DONE DISCOVERY on port %d, pid:%d, result:%d\n", port->id,
  		    task_pid_nr(current), error);
  }
@@ -523,6 +525,10 @@ static void sas_revalidate_domain(struct
  		    port->id, task_pid_nr(current), res);
   out:
  	mutex_unlock(&ha->disco_mutex);
+
+	sas_destruct_devices(port);
+	sas_destruct_ports(port);
+	sas_probe_devices(port);
  }
 
  /* ---------- Events ---------- */
@@ -578,10 +584,8 @@ void sas_init_disc(struct sas_discovery
  	static const work_func_t sas_event_fns[DISC_NUM_EVENTS] = {
  		[DISCE_DISCOVER_DOMAIN] = sas_discover_domain,
  		[DISCE_REVALIDATE_DOMAIN] = sas_revalidate_domain,
-		[DISCE_PROBE] = sas_probe_devices,
  		[DISCE_SUSPEND] = sas_suspend_devices,
  		[DISCE_RESUME] = sas_resume_devices,
-		[DISCE_DESTRUCT] = sas_destruct_devices,
  	};
 
  	disc->pending = 0;
drivers/scsi/libsas/sas_expander.c +3 -5
@@ -1903,7 +1903,8 @@ static void sas_unregister_devs_sas_addr
  		sas_port_delete_phy(phy->port, phy->phy);
  		sas_device_set_phy(found, phy->port);
  		if (phy->port->num_phys == 0)
-			sas_port_delete(phy->port);
+			list_add_tail(&phy->port->del_list,
+				&parent->port->sas_port_del_list);
  		phy->port = NULL;
  	}
  }
@@ -2111,7 +2112,7 @@ int sas_ex_revalidate_domain(struct doma
  	struct domain_device *dev = NULL;
 
  	res = sas_find_bcast_dev(port_dev, &dev);
-	while (res == 0 && dev) {
+	if (res == 0 && dev) {
  		struct expander_device *ex = &dev->ex_dev;
  		int i = 0, phy_id;
 
@@ -2123,9 +2124,6 @@ int sas_ex_revalidate_domain(struct doma
  			res = sas_rediscover(dev, phy_id);
  			i = phy_id + 1;
  		} while (i < ex->num_phys);
-
-		dev = NULL;
-		res = sas_find_bcast_dev(port_dev, &dev);
  	}
  	return res;
  }
drivers/scsi/libsas/sas_internal.h +1 -0
@@ -100,6 +100,7 @@ int sas_try_ata_reset(struct asd_sas_phy
  void sas_hae_reset(struct work_struct *work);
 
  void sas_free_device(struct kref *kref);
+void sas_destruct_devices(struct asd_sas_port *port);
 
  #ifdef CONFIG_SCSI_SAS_HOST_SMP
  extern int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
drivers/scsi/libsas/sas_port.c +3 -0
@@ -66,6 +66,7 @@ static void sas_resume_port(struct asd_s
  		rc = sas_notify_lldd_dev_found(dev);
  		if (rc) {
  			sas_unregister_dev(port, dev);
+			sas_destruct_devices(port);
  			continue;
  		}
 
@@ -219,6 +220,7 @@ void sas_deform_port(struct asd_sas_phy
 
  	if (port->num_phys == 1) {
  		sas_unregister_domain_devices(port, gone);
+		sas_destruct_devices(port);
  		sas_port_delete(port->port);
  		port->port = NULL;
  	} else {
@@ -323,6 +325,7 @@ static void sas_init_port(struct asd_sas
  	INIT_LIST_HEAD(&port->dev_list);
  	INIT_LIST_HEAD(&port->disco_list);
  	INIT_LIST_HEAD(&port->destroy_list);
+	INIT_LIST_HEAD(&port->sas_port_del_list);
  	spin_lock_init(&port->phy_list_lock);
  	INIT_LIST_HEAD(&port->phy_list);
  	port->ha = sas_ha;
include/scsi/libsas.h +1 -2
@@ -87,10 +87,8 @@ enum discover_event {
  	DISCE_DISCOVER_DOMAIN   = 0U,
  	DISCE_REVALIDATE_DOMAIN,
  	DISCE_PORT_GONE,
-	DISCE_PROBE,
  	DISCE_SUSPEND,
  	DISCE_RESUME,
-	DISCE_DESTRUCT,
  	DISC_NUM_EVENTS,
  };
 
@@ -274,6 +272,7 @@ struct asd_sas_port {
  	struct list_head dev_list;
  	struct list_head disco_list;
  	struct list_head destroy_list;
+	struct list_head sas_port_del_list;
  	enum   sas_linkrate linkrate;
 
  	struct sas_work work;
include/scsi/scsi_transport_sas.h +1 -0
@@ -145,6 +145,7 @@ struct sas_port {
 
  	struct mutex		phy_list_mutex;
  	struct list_head	phy_list;
+	struct list_head	del_list; /* libsas only */
  };
 
  #define dev_to_sas_port(d) \

.

Signature · 3 lines
Ben Hutchings
The generation of random numbers is too important to be left to chance.
                                                       - Robert Coveyou
#17 lore raw

PATCH 13/410 f2fs: fix a panic caused by NULL flush_cmd_control

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Yunlei He <[email protected]>

commit d4fdf8ba0e5808ba9ad6b44337783bd9935e0982 upstream.

Mount fs with option noflush_merge, boot failed for illegal address fcc in function f2fs_issue_flush:

        if (!test_opt(sbi, FLUSH_MERGE)) {
                ret = submit_flush_wait(sbi);
                atomic_inc(&fcc->issued_flush);   ->  Here, fcc illegal
                return ret;
        }
[bwh: Backported to 3.16: adjust context]
---
 fs/f2fs/segment.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/f2fs/segment.c +4 -1
@@ -273,6 +273,9 @@ int create_flush_cmd_control(struct f2fs
 	spin_lock_init(&fcc->issue_lock);
 	init_waitqueue_head(&fcc->flush_wait_queue);
 	sbi->sm_info->cmd_control_info = fcc;
+	if (!test_opt(sbi, FLUSH_MERGE))
+		return err;
+
 	fcc->f2fs_issue_flush = kthread_run(issue_flush_thread, sbi,
 				"f2fs_flush-%u:%u", MAJOR(dev), MINOR(dev));
 	if (IS_ERR(fcc->f2fs_issue_flush)) {
@@ -1905,7 +1908,7 @@ int build_segment_manager(struct f2fs_sb
 	sm_info->nr_discards = 0;
 	sm_info->max_discards = 0;
 
-	if (test_opt(sbi, FLUSH_MERGE) && !f2fs_readonly(sbi->sb)) {
+	if (!f2fs_readonly(sbi->sb)) {
 		err = create_flush_cmd_control(sbi);
 		if (err)
 			return err;
#18 lore raw

PATCH 14/410 cifs: empty TargetInfo leads to crash on recovery

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Dan Aloni <[email protected]>

commit cabfb3680f78981d26c078a26e5c748531257ebb upstream.

[ resend from Oct 20, 2014, see [1] ]

A trivially patched Samba server (see [2] [3]) can cause a remote kernel crash (see [4]) in a client's CIFS kernel module upon session recovery, under kernels prior to v4.11. The server patch can made by a single source line modification - returning an empty TargetInfo in an NTLMSSP setup negotiation response.

To reproduce at the client side, the CIFS client can be instructed to mount with SMB 2.0, on a share without user/password credentials, e.g:

     mount -t cifs //[host]/[share] -o vers=2.0,guest [mountpoint]

(It may also reproduce with credentials, but I used a simpler
configuration for the reproduction)

An demo patch to Samba 4.7.4 is provided in the links provided.

As for the client crash itself:

When the session is recovered (after a server start/stop, for example), the following condition turns out to be true:

     ses->auth_key.len != 0  &&  ses->auth_key.response == NULL

This will cause the following memcpy() in setup_ntlmv2_rsp() to GPF, because tiblob == NULL and tilen != 0 (these are the old auth_key values):

     memcpy(ses->auth_key.response + baselen, tiblob, tilen);

By bisecting, upstream commit cabfb3680f78 ("CIFS: Enable encryption during session setup phase") from v4.11 have fixed this issue.

According to my tests, LTS kernels versions 4.4.x and 4.9.x are affected. The patch below applies for 4.4.x however a similar patch can be applied to 4.9.x and older kernels.

[1]
https://patchwork.kernel.org/patch/5106391/

[2] (temporary url)
http://copr-dist-git.fedorainfracloud.org/cgit/alonid/samba-for-client-crash-repro/samba.git/tree/0001-Patch.patch?id=43229c84abe008bfc11aa86f5bacb03a1e54f88c

[3] (temporary url)
https://copr.fedorainfracloud.org/coprs/alonid/samba-for-client-crash-repro/

[4]

[ 3414.518134] BUG: unable to handle kernel NULL pointer dereference at           (null)
[ 3414.518200] IP: memcpy_erms+0x6/0x10
[ 3414.518227] PGD 0
[ 3414.518252] Oops: 0000 [#1] SMP
[ 3414.518272] Modules linked in: arc4 md4 cifs rpcsec_gss_krb5 nfsv4 dns_resolver nfs fscache ip6t_rpfilter ip6t_REJECT nf_reject_ipv6 xt_conntrack ip_set nfnetlink ebtable_nat ebtable_broute bridge stp llc ip6table_nat nf_conntrack_ipv6 nf_defrag_ipv6 nf_nat_ipv6 ip6table_mangle ip6table_security ip6table_raw iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack iptable_mangle iptable_security iptable_raw ebtable_filter ebtables ip6table_filter ip6_tables snd_hda_codec_generic ppdev snd_hda_intel snd_hda_codec crct10dif_pclmul crc32_pclmul snd_hwdep snd_hda_core ghash_clmulni_intel snd_seq snd_seq_device snd_pcm joydev parport_pc tpm_tis parport tpm_tis_core tpm snd_timer snd soundcore qemu_fw_cfg virtio_balloon i2c_piix4 nfsd auth_rpcgss nfs_acl lockd grace sunrpc
  xfs libcrc32c
[ 3414.518708]  virtio_blk virtio_console virtio_net qxl drm_kms_helper ttm crc32c_intel drm ata_generic nvme serio_raw nvme_core virtio_pci virtio_ring virtio pata_acpi
[ 3414.518803] CPU: 3 PID: 1697 Comm: kworker/3:1 Not tainted 4.10.0-rc6-dan-00097-ge765a3d89ede #20
[ 3414.518852] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-2.fc27 04/01/2014
[ 3414.518927] Workqueue: cifsiod smb2_reconnect_server [cifs]
[ 3414.518960] task: ffff8cc6764a4000 task.stack: ffff9bc548808000
[ 3414.518997] RIP: 0010:memcpy_erms+0x6/0x10
[ 3414.519021] RSP: 0018:ffff9bc54880bbc8 EFLAGS: 00010296
[ 3414.519051] RAX: ffff8cc6ba00d8dc RBX: ffff8cc676190400 RCX: 0000000000000010
[ 3414.519091] RDX: 0000000000000010 RSI: 0000000000000000 RDI: ffff8cc6ba00d8dc
[ 3414.519130] RBP: ffff9bc54880bc30 R08: ffff9bc54880bb58 R09: ffff9bc54880bb58
[ 3414.519170] R10: 000000004619520e R11: 00000000f46cd8cf R12: 0000000000000000
[ 3414.519209] R13: 0000000000000000 R14: ffff8cc6ba00d8a0 R15: 0000000000000010
[ 3414.519250] FS:  0000000000000000(0000) GS:ffff8cc6bfd80000(0000) knlGS:0000000000000000
[ 3414.519314] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 3414.519347] CR2: 0000000000000000 CR3: 000000007992a000 CR4: 00000000003406e0
[ 3414.519392] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 3414.519431] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[ 3414.519470] Call Trace:
[ 3414.519510]  ? setup_ntlmv2_rsp+0x124/0xa10 [cifs]
[ 3414.519553]  build_ntlmssp_auth_blob+0x36/0x310 [cifs]
[ 3414.519597]  SMB2_sess_auth_rawntlmssp_authenticate+0xc7/0x300 [cifs]
[ 3414.519646]  SMB2_sess_setup+0x9a/0x140 [cifs]
[ 3414.519685]  cifs_setup_session+0x78/0x100 [cifs]
[ 3414.519722]  ? cifs_negotiate_protocol+0x84/0xd0 [cifs]
[ 3414.519763]  smb2_reconnect+0x308/0x3e0 [cifs]
[ 3414.519793]  ? __internal_add_timer+0x1f/0x60
[ 3414.519831]  smb2_reconnect_server+0x187/0x260 [cifs]
[ 3414.519863]  process_one_work+0x19e/0x440
[ 3414.519887]  worker_thread+0x4e/0x4a0
[ 3414.519910]  ? process_one_work+0x440/0x440
[ 3414.519936]  kthread+0x11e/0x140
[ 3414.520493]  ? kthread_park+0x90/0x90
[ 3414.520989]  ret_from_fork+0x2c/0x40
[ 3414.521450] Code: 78 ff ff ff 90 eb 1e 0f 1f 00 48 89 f8 48 89 d1 48 c1 e9 03 83 e2 07 f3 48 a5 89 d1 f3 a4 c3 66 0f 1f 44 00 00 48 89 f8 48 89 d1 <f3> a4 c3 0f 1f 80 00 00 00 00 48 89 f8 48 83 fa 20 72 7e 40 38
[ 3414.522488] RIP: memcpy_erms+0x6/0x10 RSP: ffff9bc54880bbc8
[ 3414.522964] CR2: 0000000000000000
[ 3414.526127] ---[ end trace bbe4aa1e45cc6c17 ]---
---
 fs/cifs/smb2pdu.c | 3 +++
 1 file changed, 3 insertions(+)
fs/cifs/smb2pdu.c +3 -0
@@ -596,6 +596,7 @@ SMB2_sess_setup(const unsigned int xid,
 	 */
 	kfree(ses->auth_key.response);
 	ses->auth_key.response = NULL;
+	ses->auth_key.len = 0;
 
 	/*
 	 * If memory allocation is successful, caller of this function
@@ -756,6 +757,7 @@ ssetup_exit:
 			rc = server->ops->generate_signingkey(ses);
 			kfree(ses->auth_key.response);
 			ses->auth_key.response = NULL;
+			ses->auth_key.len = 0;
 			if (rc) {
 				cifs_dbg(FYI,
 					"SMB3 session key generation failed\n");
@@ -780,6 +782,7 @@ keygen_exit:
 	if (!server->sign) {
 		kfree(ses->auth_key.response);
 		ses->auth_key.response = NULL;
+		ses->auth_key.len = 0;
 	}
 	kfree(ses->ntlmssp);
 
#19 lore raw

PATCH 15/410 netfilter: ebtables: CONFIG_COMPAT: don't trust userland offsets

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Florian Westphal <[email protected]>

commit b71812168571fa55e44cdd0254471331b9c4c4c6 upstream.

We need to make sure the offsets are not out of range of the total size.
Also check that they are in ascending order.

The WARN_ON triggered by syzkaller (it sets panic_on_warn) is changed to also bail out, no point in continuing parsing.

Briefly tested with simple ruleset of
-A INPUT --limit 1/s' --log
plus jump to custom chains using 32bit ebtables binary.

---
 net/bridge/netfilter/ebtables.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
net/bridge/netfilter/ebtables.c +12 -1
@@ -2010,7 +2010,9 @@ static int ebt_size_mwt(struct compat_eb
 		if (match_kern)
 			match_kern->match_size = ret;
 
-		WARN_ON(type == EBT_COMPAT_TARGET && size_left);
+		if (WARN_ON(type == EBT_COMPAT_TARGET && size_left))
+			return -EINVAL;
+
 		match32 = (struct compat_ebt_entry_mwt *) buf;
 	}
 
@@ -2067,6 +2069,15 @@ static int size_entry_mwt(struct ebt_ent
 	 *
 	 * offsets are relative to beginning of struct ebt_entry (i.e., 0).
 	 */
+	for (i = 0; i < 4 ; ++i) {
+		if (offsets[i] >= *total)
+			return -EINVAL;
+		if (i == 0)
+			continue;
+		if (offsets[i-1] > offsets[i])
+			return -EINVAL;
+	}
+
 	for (i = 0, j = 1 ; j < 4 ; j++, i++) {
 		struct compat_ebt_entry_mwt *match32;
 		unsigned int size;
#20 lore raw

PATCH 16/410 netfilter: ebtables: fix erroneous reject of last rule

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Florian Westphal <[email protected]>

commit 932909d9b28d27e807ff8eecb68c7748f6701628 upstream.

The last rule in the blob has next_entry offset that is same as total size. This made "ebtables32 -A OUTPUT -d de:ad:be:ef:01:02" fail on 64 bit kernel.

Fixes b71812168571fa ("netfilter: ebtables: CONFIG_COMPAT: don't trust userland offsets")
---
 net/bridge/netfilter/ebtables.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
net/bridge/netfilter/ebtables.c +5 -1
@@ -2070,8 +2070,12 @@ static int size_entry_mwt(struct ebt_ent
 	 * offsets are relative to beginning of struct ebt_entry (i.e., 0).
 	 */
 	for (i = 0; i < 4 ; ++i) {
-		if (offsets[i] >= *total)
+		if (offsets[i] > *total)
 			return -EINVAL;
+
+		if (i < 3 && offsets[i] == *total)
+			return -EINVAL;
+
 		if (i == 0)
 			continue;
 		if (offsets[i-1] > offsets[i])
#21 lore raw

PATCH 17/410 kvm/x86: fix icebp instruction handling

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Linus Torvalds <[email protected]>

commit 32d43cd391bacb5f0814c2624399a5dad3501d09 upstream.

The undocumented 'icebp' instruction (aka 'int1') works pretty much like 'int3' in the absense of in-circuit probing equipment (except, obviously, that it raises #DB instead of raising #BP), and is used by some validation test-suites as such.

But Andy Lutomirski noticed that his test suite acted differently in kvm than on bare hardware.

The reason is that kvm used an inexact test for the icebp instruction:
it just assumed that an all-zero VM exit qualification value meant that the VM exit was due to icebp.

That is not unlike the guess that do_debug() does for the actual exception handling case, but it's purely a heuristic, not an absolute rule. do_debug() does it because it wants to ascribe _some_ reasons to the #DB that happened, and an empty %dr6 value means that 'icebp' is the most likely casue and we have no better information.

But kvm can just do it right, because unlike the do_debug() case, kvm actually sees the real reason for the #DB in the VM-exit interruption information field.

So instead of relying on an inexact heuristic, just use the actual VM exit information that says "it was 'icebp'".

Right now the 'icebp' instruction isn't technically documented by Intel, but that will hopefully change. The special "privileged software exception" information _is_ actually mentioned in the Intel SDM, even though the cause of it isn't enumerated.

---
 arch/x86/include/asm/vmx.h | 1 +
 arch/x86/kvm/vmx.c         | 9 ++++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)
arch/x86/include/asm/vmx.h +1 -0
@@ -296,6 +296,7 @@ enum vmcs_field {
 #define INTR_TYPE_NMI_INTR		(2 << 8) /* NMI */
 #define INTR_TYPE_HARD_EXCEPTION	(3 << 8) /* processor exception */
 #define INTR_TYPE_SOFT_INTR             (4 << 8) /* software interrupt */
+#define INTR_TYPE_PRIV_SW_EXCEPTION	(5 << 8) /* ICE breakpoint - undocumented */
 #define INTR_TYPE_SOFT_EXCEPTION	(6 << 8) /* software exception */
 
 /* GUEST_INTERRUPTIBILITY_INFO flags. */
arch/x86/kvm/vmx.c +8 -1
@@ -868,6 +868,13 @@ static inline bool is_machine_check(u32
 		(INTR_TYPE_HARD_EXCEPTION | MC_VECTOR | INTR_INFO_VALID_MASK);
 }
 
+/* Undocumented: icebp/int1 */
+static inline bool is_icebp(u32 intr_info)
+{
+	return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VALID_MASK))
+		== (INTR_TYPE_PRIV_SW_EXCEPTION | INTR_INFO_VALID_MASK);
+}
+
 static inline bool cpu_has_vmx_msr_bitmap(void)
 {
 	return vmcs_config.cpu_based_exec_ctrl & CPU_BASED_USE_MSR_BITMAPS;
@@ -4915,7 +4922,7 @@ static int handle_exception(struct kvm_v
 		      (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP))) {
 			vcpu->arch.dr6 &= ~15;
 			vcpu->arch.dr6 |= dr6;
-			if (!(dr6 & ~DR6_RESERVED)) /* icebp */
+			if (is_icebp(intr_info))
 				skip_emulated_instruction(vcpu);
 
 			kvm_queue_exception(vcpu, DB_VECTOR);
#22 lore raw

PATCH 18/410 ext4: fail ext4_iget for root directory if unallocated

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Theodore Ts'o <[email protected]>

commit 8e4b5eae5decd9dfe5a4ee369c22028f90ab4c44 upstream.

If the root directory has an i_links_count of zero, then when the file system is mounted, then when ext4_fill_super() notices the problem and tries to call iput() the root directory in the error return path, ext4_evict_inode() will try to free the inode on disk, before all of the file system structures are set up, and this will result in an OOPS caused by a NULL pointer dereference.

This issue has been assigned CVE-2018-1092.

https://bugzilla.kernel.org/show_bug.cgi?id=199179
https://bugzilla.redhat.com/show_bug.cgi?id=1560777

[bwh: Backported to 3.16: use EIO instead of EFSCORRUPTED]
---
 fs/ext4/inode.c |    6 ++++++
 1 file changed, 6 insertions(+)
fs/ext4/inode.c +6 -0
@@ -4198,6 +4198,12 @@ struct inode *ext4_iget(struct super_blo
 		goto bad_inode;
 	raw_inode = ext4_raw_inode(&iloc);
 
+	if ((ino == EXT4_ROOT_INO) && (raw_inode->i_links_count == 0)) {
+		EXT4_ERROR_INODE(inode, "root inode unallocated");
+		ret = -EIO;
+		goto bad_inode;
+	}
+
 	if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) {
 		ei->i_extra_isize = le16_to_cpu(raw_inode->i_extra_isize);
 		if (EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize >
#23 lore raw

PATCH 19/410 ext4: add validity checks for bitmap block numbers

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Theodore Ts'o <[email protected]>

commit 7dac4a1726a9c64a517d595c40e95e2d0d135f6f upstream.

An privileged attacker can cause a crash by mounting a crafted ext4 image which triggers a out-of-bounds read in the function ext4_valid_block_bitmap() in fs/ext4/balloc.c.

This issue has been assigned CVE-2018-1093.

[bwh: Backported to 3.16:
- In ext4_read_block_bitmap_nowait() and ext4_read_inode_bitmap(), return NULL on error
- Adjust context]

---

fs/ext4/balloc.c +14 -2
@@ -340,20 +340,25 @@ static ext4_fsblk_t ext4_valid_block_bit
 	/* check whether block bitmap block number is set */
 	blk = ext4_block_bitmap(sb, desc);
 	offset = blk - group_first_block;
-	if (!ext4_test_bit(EXT4_B2C(sbi, offset), bh->b_data))
+	if (offset < 0 || EXT4_B2C(sbi, offset) >= sb->s_blocksize ||
+	    !ext4_test_bit(EXT4_B2C(sbi, offset), bh->b_data))
 		/* bad block bitmap */
 		return blk;
 
 	/* check whether the inode bitmap block number is set */
 	blk = ext4_inode_bitmap(sb, desc);
 	offset = blk - group_first_block;
-	if (!ext4_test_bit(EXT4_B2C(sbi, offset), bh->b_data))
+	if (offset < 0 || EXT4_B2C(sbi, offset) >= sb->s_blocksize ||
+	    !ext4_test_bit(EXT4_B2C(sbi, offset), bh->b_data))
 		/* bad block bitmap */
 		return blk;
 
 	/* check whether the inode table block number is set */
 	blk = ext4_inode_table(sb, desc);
 	offset = blk - group_first_block;
+	if (offset < 0 || EXT4_B2C(sbi, offset) >= sb->s_blocksize ||
+	    EXT4_B2C(sbi, offset + sbi->s_itb_per_group) >= sb->s_blocksize)
+		return blk;
 	next_zero_bit = ext4_find_next_zero_bit(bh->b_data,
 			EXT4_B2C(sbi, offset + EXT4_SB(sb)->s_itb_per_group),
 			EXT4_B2C(sbi, offset));
@@ -416,6 +421,7 @@ struct buffer_head *
 ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group)
 {
 	struct ext4_group_desc *desc;
+	struct ext4_sb_info *sbi = EXT4_SB(sb);
 	struct buffer_head *bh;
 	ext4_fsblk_t bitmap_blk;
 
@@ -423,6 +429,12 @@ ext4_read_block_bitmap_nowait(struct sup
 	if (!desc)
 		return NULL;
 	bitmap_blk = ext4_block_bitmap(sb, desc);
+	if ((bitmap_blk <= le32_to_cpu(sbi->s_es->s_first_data_block)) ||
+	    (bitmap_blk >= ext4_blocks_count(sbi->s_es))) {
+		ext4_error(sb, "Invalid block bitmap block %llu in "
+			   "block_group %u", bitmap_blk, block_group);
+		return NULL;
+	}
 	bh = sb_getblk(sb, bitmap_blk);
 	if (unlikely(!bh)) {
 		ext4_error(sb, "Cannot get buffer for block bitmap - "
fs/ext4/ialloc.c +6 -0
@@ -133,6 +133,12 @@ ext4_read_inode_bitmap(struct super_bloc
 		return NULL;
 
 	bitmap_blk = ext4_inode_bitmap(sb, desc);
+	if ((bitmap_blk <= le32_to_cpu(sbi->s_es->s_first_data_block)) ||
+	    (bitmap_blk >= ext4_blocks_count(sbi->s_es))) {
+		ext4_error(sb, "Invalid inode bitmap blk %llu in "
+			   "block_group %u", bitmap_blk, block_group);
+		return NULL;
+	}
 	bh = sb_getblk(sb, bitmap_blk);
 	if (unlikely(!bh)) {
 		ext4_error(sb, "Cannot read inode bitmap - "
#24 lore raw

PATCH 20/410 ext4: fix bitmap position validation

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Lukas Czerner <[email protected]>

commit 22be37acce25d66ecf6403fc8f44df9c5ded2372 upstream.

Currently in ext4_valid_block_bitmap() we expect the bitmap to be positioned anywhere between 0 and s_blocksize clusters, but that's wrong because the bitmap can be placed anywhere in the block group. This causes false positives when validating bitmaps on perfectly valid file system layouts. Fix it by checking whether the bitmap is within the group boundary.

The problem can be reproduced using the following

mkfs -t ext3 -E stride=256 /dev/vdb1
mount /dev/vdb1 /mnt/test
cd /mnt/test
wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.16.3.tar.xz
tar xf linux-4.16.3.tar.xz

This will result in the warnings in the logs

EXT4-fs error (device vdb1): ext4_validate_block_bitmap:399: comm tar: bg 84: block 2774529: invalid block bitmap

[ Changed slightly for clarity and to not drop a overflow test -- TYT ]

Fixes 7dac4a1726a9 ("ext4: add validity checks for bitmap block numbers")
---
 fs/ext4/balloc.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
fs/ext4/balloc.c +5 -4
@@ -323,6 +323,7 @@ static ext4_fsblk_t ext4_valid_block_bit
 	struct ext4_sb_info *sbi = EXT4_SB(sb);
 	ext4_grpblk_t offset;
 	ext4_grpblk_t next_zero_bit;
+	ext4_grpblk_t max_bit = EXT4_CLUSTERS_PER_GROUP(sb);
 	ext4_fsblk_t blk;
 	ext4_fsblk_t group_first_block;
 
@@ -340,7 +341,7 @@ static ext4_fsblk_t ext4_valid_block_bit
 	/* check whether block bitmap block number is set */
 	blk = ext4_block_bitmap(sb, desc);
 	offset = blk - group_first_block;
-	if (offset < 0 || EXT4_B2C(sbi, offset) >= sb->s_blocksize ||
+	if (offset < 0 || EXT4_B2C(sbi, offset) >= max_bit ||
 	    !ext4_test_bit(EXT4_B2C(sbi, offset), bh->b_data))
 		/* bad block bitmap */
 		return blk;
@@ -348,7 +349,7 @@ static ext4_fsblk_t ext4_valid_block_bit
 	/* check whether the inode bitmap block number is set */
 	blk = ext4_inode_bitmap(sb, desc);
 	offset = blk - group_first_block;
-	if (offset < 0 || EXT4_B2C(sbi, offset) >= sb->s_blocksize ||
+	if (offset < 0 || EXT4_B2C(sbi, offset) >= max_bit ||
 	    !ext4_test_bit(EXT4_B2C(sbi, offset), bh->b_data))
 		/* bad block bitmap */
 		return blk;
@@ -356,8 +357,8 @@ static ext4_fsblk_t ext4_valid_block_bit
 	/* check whether the inode table block number is set */
 	blk = ext4_inode_table(sb, desc);
 	offset = blk - group_first_block;
-	if (offset < 0 || EXT4_B2C(sbi, offset) >= sb->s_blocksize ||
-	    EXT4_B2C(sbi, offset + sbi->s_itb_per_group) >= sb->s_blocksize)
+	if (offset < 0 || EXT4_B2C(sbi, offset) >= max_bit ||
+	    EXT4_B2C(sbi, offset + sbi->s_itb_per_group) >= max_bit)
 		return blk;
 	next_zero_bit = ext4_find_next_zero_bit(bh->b_data,
 			EXT4_B2C(sbi, offset + EXT4_SB(sb)->s_itb_per_group),
#25 lore raw

PATCH 21/410 dccp: check sk for closed state in dccp_sendmsg()

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Alexey Kodanev <[email protected]>

commit 67f93df79aeefc3add4e4b31a752600f834236e2 upstream.

dccp_disconnect() sets 'dp->dccps_hc_tx_ccid' tx handler to NULL, therefore if DCCP socket is disconnected and dccp_sendmsg() is called after it, it will cause a NULL pointer dereference in dccp_write_xmit().

This crash and the reproducer was reported by syzbot. Looks like it is reproduced if commit 69c64866ce07 ("dccp: CVE-2017-8824:
use-after-free in DCCP code") is applied.

---
 net/dccp/proto.c | 5 +++++
 1 file changed, 5 insertions(+)
net/dccp/proto.c +5 -0
@@ -785,6 +785,11 @@ int dccp_sendmsg(struct kiocb *iocb, str
 	if (skb == NULL)
 		goto out_release;
 
+	if (sk->sk_state == DCCP_CLOSED) {
+		rc = -ENOTCONN;
+		goto out_discard;
+	}
+
 	skb_reserve(skb, sk->sk_prot->max_header);
 	rc = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
 	if (rc != 0)
#26 lore raw

PATCH 22/410 sctp: verify size of a new chunk in _sctp_make_chunk()

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Alexey Kodanev <[email protected]>

commit 07f2c7ab6f8d0a7e7c5764c4e6cc9c52951b9d9c upstream.

When SCTP makes INIT or INIT_ACK packet the total chunk length can exceed SCTP_MAX_CHUNK_LEN which leads to kernel panic when transmitting these packets, e.g. the crash on sending INIT_ACK:

[  597.804948] skbuff: skb_over_panic: text:00000000ffae06e4 len:120168
               put:120156 head:000000007aa47635 data:00000000d991c2de
               tail:0x1d640 end:0xfec0 dev:<NULL>
...
[  597.976970] ------------[ cut here ]------------
[  598.033408] kernel BUG at net/core/skbuff.c:104!
[  600.314841] Call Trace:
[  600.345829]  <IRQ>
[  600.371639]  ? sctp_packet_transmit+0x2095/0x26d0 [sctp]
[  600.436934]  skb_put+0x16c/0x200
[  600.477295]  sctp_packet_transmit+0x2095/0x26d0 [sctp]
[  600.540630]  ? sctp_packet_config+0x890/0x890 [sctp]
[  600.601781]  ? __sctp_packet_append_chunk+0x3b4/0xd00 [sctp]
[  600.671356]  ? sctp_cmp_addr_exact+0x3f/0x90 [sctp]
[  600.731482]  sctp_outq_flush+0x663/0x30d0 [sctp]
[  600.788565]  ? sctp_make_init+0xbf0/0xbf0 [sctp]
[  600.845555]  ? sctp_check_transmitted+0x18f0/0x18f0 [sctp]
[  600.912945]  ? sctp_outq_tail+0x631/0x9d0 [sctp]
[  600.969936]  sctp_cmd_interpreter.isra.22+0x3be1/0x5cb0 [sctp]
[  601.041593]  ? sctp_sf_do_5_1B_init+0x85f/0xc30 [sctp]
[  601.104837]  ? sctp_generate_t1_cookie_event+0x20/0x20 [sctp]
[  601.175436]  ? sctp_eat_data+0x1710/0x1710 [sctp]
[  601.233575]  sctp_do_sm+0x182/0x560 [sctp]
[  601.284328]  ? sctp_has_association+0x70/0x70 [sctp]
[  601.345586]  ? sctp_rcv+0xef4/0x32f0 [sctp]
[  601.397478]  ? sctp6_rcv+0xa/0x20 [sctp]

...

Here the chunk size for INIT_ACK packet becomes too big, mostly because of the state cookie (INIT packet has large size with many address parameters), plus additional server parameters.

Later this chunk causes the panic in skb_put_data():

  skb_packet_transmit()
      sctp_packet_pack()
          skb_put_data(nskb, chunk->skb->data, chunk->skb->len);

'nskb' (head skb) was previously allocated with packet->size from u16 'chunk->chunk_hdr->length'.

As suggested by Marcelo we should check the chunk's length in _sctp_make_chunk() before trying to allocate skb for it and discard a chunk if its size bigger than SCTP_MAX_CHUNK_LEN.

[bwh: Backported to 3.16:
- Keep using WORD_ROUND() instead of SCTP_PAD4()
- Adjust context]

---
 net/sctp/sm_make_chunk.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
net/sctp/sm_make_chunk.c +6 -2
@@ -1367,10 +1367,14 @@ static struct sctp_chunk *_sctp_make_chu
 	sctp_chunkhdr_t *chunk_hdr;
 	struct sk_buff *skb;
 	struct sock *sk;
+	int chunklen;
+
+	chunklen = WORD_ROUND(sizeof(*chunk_hdr) + paylen);
+	if (chunklen > SCTP_MAX_CHUNK_LEN)
+		goto nodata;
 
 	/* No need to allocate LL here, as this is only a chunk. */
-	skb = alloc_skb(WORD_ROUND(sizeof(sctp_chunkhdr_t) + paylen),
-			GFP_ATOMIC);
+	skb = alloc_skb(chunklen, GFP_ATOMIC);
 	if (!skb)
 		goto nodata;
 
#27 lore raw

PATCH 23/410 fbdev: Fixing arbitrary kernel leak in case FBIOGETCMAP_SPARC in sbusfb_ioctl_helper().

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Peter Malone <[email protected]>

commit 250c6c49e3b68756b14983c076183568636e2bde upstream.

Fixing arbitrary kernel leak in case FBIOGETCMAP_SPARC in sbusfb_ioctl_helper().

'index' is defined as an int in sbusfb_ioctl_helper(). We retrieve this from the user:
if (get_user(index, &c->index) ||

    __get_user(count, &c->count) ||
    __get_user(ured, &c->red) ||
    __get_user(ugreen, &c->green) ||
    __get_user(ublue, &c->blue))
       return -EFAULT;

and then we use 'index' in the following way:
red = cmap->red[index + i] >> 8;
green = cmap->green[index + i] >> 8;
blue = cmap->blue[index + i] >> 8;

This is a classic information leak vulnerability. 'index' should be an unsigned int, given its usage above.

This patch is straight-forward; it changes 'index' to unsigned int in two switch-cases: FBIOGETCMAP_SPARC && FBIOPUTCMAP_SPARC.

This patch fixes CVE-2018-6412.

---
 drivers/video/fbdev/sbuslib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/video/fbdev/sbuslib.c +2 -2
@@ -121,7 +121,7 @@ int sbusfb_ioctl_helper(unsigned long cm
 		unsigned char __user *ured;
 		unsigned char __user *ugreen;
 		unsigned char __user *ublue;
-		int index, count, i;
+		unsigned int index, count, i;
 
 		if (get_user(index, &c->index) ||
 		    __get_user(count, &c->count) ||
@@ -160,7 +160,7 @@ int sbusfb_ioctl_helper(unsigned long cm
 		unsigned char __user *ugreen;
 		unsigned char __user *ublue;
 		struct fb_cmap *cmap = &info->cmap;
-		int index, count, i;
+		unsigned int index, count, i;
 		u8 red, green, blue;
 
 		if (get_user(index, &c->index) ||
#28 lore raw

PATCH 24/410 ALSA: seq: Fix racy pool initializations

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Takashi Iwai <[email protected]>

commit d15d662e89fc667b90cd294b0eb45694e33144da upstream.

ALSA sequencer core initializes the event pool on demand by invoking snd_seq_pool_init() when the first write happens and the pool is empty. Meanwhile user can reset the pool size manually via ioctl concurrently, and this may lead to UAF or out-of-bound accesses since the function tries to vmalloc / vfree the buffer.

A simple fix is to just wrap the snd_seq_pool_init() call with the recently introduced client->ioctl_mutex; as the calls for snd_seq_pool_init() from other side are always protected with this mutex, we can avoid the race.

---
 sound/core/seq/seq_clientmgr.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
sound/core/seq/seq_clientmgr.c +6 -2
@@ -1012,7 +1012,7 @@ static ssize_t snd_seq_write(struct file
 {
 	struct snd_seq_client *client = file->private_data;
 	int written = 0, len;
-	int err = -EINVAL;
+	int err;
 	struct snd_seq_event event;
 
 	if (!(snd_seq_file_flags(file) & SNDRV_SEQ_LFLG_OUTPUT))
@@ -1027,11 +1027,15 @@ static ssize_t snd_seq_write(struct file
 
 	/* allocate the pool now if the pool is not allocated yet */ 
 	if (client->pool->size > 0 && !snd_seq_write_pool_allocated(client)) {
-		if (snd_seq_pool_init(client->pool) < 0)
+		mutex_lock(&client->ioctl_mutex);
+		err = snd_seq_pool_init(client->pool);
+		mutex_unlock(&client->ioctl_mutex);
+		if (err < 0)
 			return -ENOMEM;
 	}
 
 	/* only process whole events */
+	err = -EINVAL;
 	while (count >= sizeof(struct snd_seq_event)) {
 		/* Read in the event header from the user */
 		len = sizeof(event);
#29 lore raw

PATCH 25/410 ALSA: seq: Don't allow resizing pool in use

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Takashi Iwai <[email protected]>

commit d85739367c6d56e475c281945c68fdb05ca74b4c upstream.

This is a fix for a (sort of) fallout in the recent commit d15d662e89fc ("ALSA: seq: Fix racy pool initializations") for CVE-2018-1000004.
As the pool resize deletes the existing cells, it may lead to a race when another thread is writing concurrently, eventually resulting a UAF.

A simple workaround is not to allow the pool resizing when the pool is in use. It's an invalid behavior in anyway.

Fixes d15d662e89fc ("ALSA: seq: Fix racy pool initializations")
---
 sound/core/seq/seq_clientmgr.c | 3 +++
 1 file changed, 3 insertions(+)
sound/core/seq/seq_clientmgr.c +3 -0
@@ -1929,6 +1929,9 @@ static int snd_seq_ioctl_set_client_pool
 	    (! snd_seq_write_pool_allocated(client) ||
 	     info.output_pool != client->pool->size)) {
 		if (snd_seq_write_pool_allocated(client)) {
+			/* is the pool in use? */
+			if (atomic_read(&client->pool->counter))
+				return -EBUSY;
 			/* remove all existing cells */
 			snd_seq_pool_mark_closing(client->pool);
 			snd_seq_queue_client_leave_cells(client->number);
#30 lore raw

PATCH 26/410 ALSA: seq: More protection for concurrent write and ioctl races

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Takashi Iwai <[email protected]>

commit 7bd80091567789f1c0cb70eb4737aac8bcd2b6b9 upstream.

This patch is an attempt for further hardening against races between the concurrent write and ioctls. The previous fix d15d662e89fc ("ALSA: seq: Fix racy pool initializations") covered the race of the pool initialization at writer and the pool resize ioctl by the client->ioctl_mutex (CVE-2018-1000004). However, basically this mutex should be applied more widely to the whole write operation for avoiding the unexpected pool operations by another thread.

The only change outside snd_seq_write() is the additional mutex argument to helper functions, so that we can unlock / relock the given mutex temporarily during schedule() call for blocking write.

Fixes d15d662e89fc ("ALSA: seq: Fix racy pool initializations")
---
 sound/core/seq/seq_clientmgr.c | 18 +++++++++++-------
 sound/core/seq/seq_fifo.c      |  2 +-
 sound/core/seq/seq_memory.c    | 14 ++++++++++----
 sound/core/seq/seq_memory.h    |  3 ++-
 4 files changed, 24 insertions(+), 13 deletions(-)
sound/core/seq/seq_clientmgr.c +11 -7
@@ -919,7 +919,8 @@ int snd_seq_dispatch_event(struct snd_se
 static int snd_seq_client_enqueue_event(struct snd_seq_client *client,
 					struct snd_seq_event *event,
 					struct file *file, int blocking,
-					int atomic, int hop)
+					int atomic, int hop,
+					struct mutex *mutexp)
 {
 	struct snd_seq_event_cell *cell;
 	int err;
@@ -957,7 +958,8 @@ static int snd_seq_client_enqueue_event(
 		return -ENXIO; /* queue is not allocated */
 
 	/* allocate an event cell */
-	err = snd_seq_event_dup(client->pool, event, &cell, !blocking || atomic, file);
+	err = snd_seq_event_dup(client->pool, event, &cell, !blocking || atomic,
+				file, mutexp);
 	if (err < 0)
 		return err;
 
@@ -1026,12 +1028,11 @@ static ssize_t snd_seq_write(struct file
 		return -ENXIO;
 
 	/* allocate the pool now if the pool is not allocated yet */ 
+	mutex_lock(&client->ioctl_mutex);
 	if (client->pool->size > 0 && !snd_seq_write_pool_allocated(client)) {
-		mutex_lock(&client->ioctl_mutex);
 		err = snd_seq_pool_init(client->pool);
-		mutex_unlock(&client->ioctl_mutex);
 		if (err < 0)
-			return -ENOMEM;
+			goto out;
 	}
 
 	/* only process whole events */
@@ -1082,7 +1083,7 @@ static ssize_t snd_seq_write(struct file
 		/* ok, enqueue it */
 		err = snd_seq_client_enqueue_event(client, &event, file,
 						   !(file->f_flags & O_NONBLOCK),
-						   0, 0);
+						   0, 0, &client->ioctl_mutex);
 		if (err < 0)
 			break;
 
@@ -1093,6 +1094,8 @@ static ssize_t snd_seq_write(struct file
 		written += len;
 	}
 
+ out:
+	mutex_unlock(&client->ioctl_mutex);
 	return written ? written : err;
 }
 
@@ -2355,7 +2358,8 @@ static int kernel_client_enqueue(int cli
 	if (! cptr->accept_output)
 		result = -EPERM;
 	else /* send it */
-		result = snd_seq_client_enqueue_event(cptr, ev, file, blocking, atomic, hop);
+		result = snd_seq_client_enqueue_event(cptr, ev, file, blocking,
+						      atomic, hop, NULL);
 
 	snd_seq_client_unlock(cptr);
 	return result;
sound/core/seq/seq_fifo.c +1 -1
@@ -123,7 +123,7 @@ int snd_seq_fifo_event_in(struct snd_seq
 		return -EINVAL;
 
 	snd_use_lock_use(&f->use_lock);
-	err = snd_seq_event_dup(f->pool, event, &cell, 1, NULL); /* always non-blocking */
+	err = snd_seq_event_dup(f->pool, event, &cell, 1, NULL, NULL); /* always non-blocking */
 	if (err < 0) {
 		if ((err == -ENOMEM) || (err == -EAGAIN))
 			atomic_inc(&f->overflow);
sound/core/seq/seq_memory.c +10 -4
@@ -221,7 +221,8 @@ void snd_seq_cell_free(struct snd_seq_ev
  */
 static int snd_seq_cell_alloc(struct snd_seq_pool *pool,
 			      struct snd_seq_event_cell **cellp,
-			      int nonblock, struct file *file)
+			      int nonblock, struct file *file,
+			      struct mutex *mutexp)
 {
 	struct snd_seq_event_cell *cell;
 	unsigned long flags;
@@ -245,7 +246,11 @@ static int snd_seq_cell_alloc(struct snd
 		set_current_state(TASK_INTERRUPTIBLE);
 		add_wait_queue(&pool->output_sleep, &wait);
 		spin_unlock_irq(&pool->lock);
+		if (mutexp)
+			mutex_unlock(mutexp);
 		schedule();
+		if (mutexp)
+			mutex_lock(mutexp);
 		spin_lock_irq(&pool->lock);
 		remove_wait_queue(&pool->output_sleep, &wait);
 		/* interrupted? */
@@ -288,7 +293,7 @@ __error:
  */
 int snd_seq_event_dup(struct snd_seq_pool *pool, struct snd_seq_event *event,
 		      struct snd_seq_event_cell **cellp, int nonblock,
-		      struct file *file)
+		      struct file *file, struct mutex *mutexp)
 {
 	int ncells, err;
 	unsigned int extlen;
@@ -305,7 +310,7 @@ int snd_seq_event_dup(struct snd_seq_poo
 	if (ncells >= pool->total_elements)
 		return -ENOMEM;
 
-	err = snd_seq_cell_alloc(pool, &cell, nonblock, file);
+	err = snd_seq_cell_alloc(pool, &cell, nonblock, file, mutexp);
 	if (err < 0)
 		return err;
 
@@ -331,7 +336,8 @@ int snd_seq_event_dup(struct snd_seq_poo
 			int size = sizeof(struct snd_seq_event);
 			if (len < size)
 				size = len;
-			err = snd_seq_cell_alloc(pool, &tmp, nonblock, file);
+			err = snd_seq_cell_alloc(pool, &tmp, nonblock, file,
+						 mutexp);
 			if (err < 0)
 				goto __error;
 			if (cell->event.data.ext.ptr == NULL)
sound/core/seq/seq_memory.h +2 -1
@@ -66,7 +66,8 @@ struct snd_seq_pool {
 void snd_seq_cell_free(struct snd_seq_event_cell *cell);
 
 int snd_seq_event_dup(struct snd_seq_pool *pool, struct snd_seq_event *event,
-		      struct snd_seq_event_cell **cellp, int nonblock, struct file *file);
+		      struct snd_seq_event_cell **cellp, int nonblock,
+		      struct file *file, struct mutex *mutexp);
 
 /* return number of unused (free) cells */
 static inline int snd_seq_unused_cells(struct snd_seq_pool *pool)
#31 lore raw

PATCH 27/410 hugetlbfs: fix offset overflow in hugetlbfs mmap

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Mike Kravetz <[email protected]>

commit 045c7a3f53d9403b62d396b6d051c4be5044cdb4 upstream.

If mmap() maps a file, it can be passed an offset into the file at which the mapping is to start. Offset could be a negative value when represented as a loff_t. The offset plus length will be used to update the file size (i_size) which is also a loff_t.

Validate the value of offset and offset + length to make sure they do not overflow and appear as negative.

Found by syzcaller with commit ff8c0c53c475 ("mm/hugetlb.c: don't call region_abort if region_chg fails") applied. Prior to this commit, the overflow would still occur but we would luckily return ENOMEM.

To reproduce:

   mmap(0, 0x2000, 0, 0x40021, 0xffffffffffffffffULL, 0x8000000000000000ULL);

Resulted in,

kernel BUG at mm/hugetlb.c:742!

  Call Trace:
   hugetlbfs_evict_inode+0x80/0xa0
   evict+0x24a/0x620
   iput+0x48f/0x8c0
   dentry_unlink_inode+0x31f/0x4d0
   __dentry_kill+0x292/0x5e0
   dput+0x730/0x830
   __fput+0x438/0x720
   ____fput+0x1a/0x20
   task_work_run+0xfe/0x180
   exit_to_usermode_loop+0x133/0x150
   syscall_return_slowpath+0x184/0x1c0
   entry_SYSCALL_64_fastpath+0xab/0xad
Fixes ff8c0c53c475 ("mm/hugetlb.c: don't call region_abort if region_chg fails")
Cc Dmitry Vyukov <[email protected]>
Cc Michal Hocko <[email protected]>
Cc "Kirill A . Shutemov" <[email protected]>
Cc Andrey Ryabinin <[email protected]>
Cc Naoya Horiguchi <[email protected]>
[bwh: Backported to 3.16: adjust context]
---
 fs/hugetlbfs/inode.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
fs/hugetlbfs/inode.c +12 -3
@@ -115,17 +115,26 @@ static int hugetlbfs_file_mmap(struct fi
 	vma->vm_flags |= VM_HUGETLB | VM_DONTEXPAND;
 	vma->vm_ops = &hugetlb_vm_ops;
 
+	/*
+	 * Offset passed to mmap (before page shift) could have been
+	 * negative when represented as a (l)off_t.
+	 */
+	if (((loff_t)vma->vm_pgoff << PAGE_SHIFT) < 0)
+		return -EINVAL;
+
 	if (vma->vm_pgoff & (~huge_page_mask(h) >> PAGE_SHIFT))
 		return -EINVAL;
 
 	vma_len = (loff_t)(vma->vm_end - vma->vm_start);
+	len = vma_len + ((loff_t)vma->vm_pgoff << PAGE_SHIFT);
+	/* check for overflow */
+	if (len < vma_len)
+		return -EINVAL;
 
 	mutex_lock(&inode->i_mutex);
 	file_accessed(file);
 
 	ret = -ENOMEM;
-	len = vma_len + ((loff_t)vma->vm_pgoff << PAGE_SHIFT);
-
 	if (hugetlb_reserve_pages(inode,
 				vma->vm_pgoff >> huge_page_order(h),
 				len >> huge_page_shift(h), vma,
@@ -135,7 +144,7 @@ static int hugetlbfs_file_mmap(struct fi
 	ret = 0;
 	hugetlb_prefault_arch_hook(vma->vm_mm);
 	if (vma->vm_flags & VM_WRITE && inode->i_size < len)
-		inode->i_size = len;
+		i_size_write(inode, len);
 out:
 	mutex_unlock(&inode->i_mutex);
 
#32 lore raw

PATCH 28/410 hugetlbfs: check for pgoff value overflow

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Mike Kravetz <[email protected]>

commit 63489f8e821144000e0bdca7e65a8d1cc23a7ee7 upstream.

A vma with vm_pgoff large enough to overflow a loff_t type when converted to a byte offset can be passed via the remap_file_pages system call. The hugetlbfs mmap routine uses the byte offset to calculate reservations and file size.

A sequence such as:

  mmap(0x20a00000, 0x600000, 0, 0x66033, -1, 0);
  remap_file_pages(0x20a00000, 0x600000, 0, 0x20000000000000, 0);

will result in the following when task exits/file closed,

kernel BUG at mm/hugetlb.c:749!

  Call Trace:
    hugetlbfs_evict_inode+0x2f/0x40
    evict+0xcb/0x190
    __dentry_kill+0xcb/0x150
    __fput+0x164/0x1e0
    task_work_run+0x84/0xa0
    exit_to_usermode_loop+0x7d/0x80
    do_syscall_64+0x18b/0x190
    entry_SYSCALL_64_after_hwframe+0x3d/0xa2

The overflowed pgoff value causes hugetlbfs to try to set up a mapping with a negative range (end < start) that leaves invalid state which causes the BUG.

The previous overflow fix to this code was incomplete and did not take the remap_file_pages system call into account.

[[email protected]: include mmdebug.h]
[[email protected]: fix -ve left shift count on sh]
Fixes 045c7a3f53d9 ("hugetlbfs: fix offset overflow in hugetlbfs mmap")
Cc "Kirill A . Shutemov" <[email protected]>
Cc Yisheng Xie <[email protected]>

[bwh: Backported to 3.16:
- Use a conditional WARN() instead of VM_WARN()
- Adjust context]

---
 fs/hugetlbfs/inode.c | 17 ++++++++++++++---
 mm/hugetlb.c         |  7 +++++++
 2 files changed, 21 insertions(+), 3 deletions(-)
fs/hugetlbfs/inode.c +14 -3
@@ -97,6 +97,16 @@ static void huge_pagevec_release(struct
 	pagevec_reinit(pvec);
 }
 
+/*
+ * Mask used when checking the page offset value passed in via system
+ * calls.  This value will be converted to a loff_t which is signed.
+ * Therefore, we want to check the upper PAGE_SHIFT + 1 bits of the
+ * value.  The extra bit (- 1 in the shift value) is to take the sign
+ * bit into account.
+ */
+#define PGOFF_LOFFT_MAX \
+	(((1UL << (PAGE_SHIFT + 1)) - 1) <<  (BITS_PER_LONG - (PAGE_SHIFT + 1)))
+
 static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma)
 {
 	struct inode *inode = file_inode(file);
@@ -116,12 +126,13 @@ static int hugetlbfs_file_mmap(struct fi
 	vma->vm_ops = &hugetlb_vm_ops;
 
 	/*
-	 * Offset passed to mmap (before page shift) could have been
-	 * negative when represented as a (l)off_t.
+	 * page based offset in vm_pgoff could be sufficiently large to
+	 * overflow a (l)off_t when converted to byte offset.
 	 */
-	if (((loff_t)vma->vm_pgoff << PAGE_SHIFT) < 0)
+	if (vma->vm_pgoff & PGOFF_LOFFT_MAX)
 		return -EINVAL;
 
+	/* must be huge page aligned */
 	if (vma->vm_pgoff & (~huge_page_mask(h) >> PAGE_SHIFT))
 		return -EINVAL;
 
mm/hugetlb.c +9 -0
@@ -19,6 +19,7 @@
 #include <linux/bootmem.h>
 #include <linux/sysfs.h>
 #include <linux/slab.h>
+#include <linux/mmdebug.h>
 #include <linux/rmap.h>
 #include <linux/swap.h>
 #include <linux/swapops.h>
@@ -3504,6 +3505,14 @@ int hugetlb_reserve_pages(struct inode *
 	struct hugepage_subpool *spool = subpool_inode(inode);
 	struct resv_map *resv_map;
 
+	/* This should never happen */
+	if (from > to) {
+#ifdef CONFIG_DEBUG_VM
+		WARN(1, "%s called with a negative range\n", __func__);
+#endif
+		return -EINVAL;
+	}
+
 	/*
 	 * Only apply hugepage reservation if asked. At fault time, an
 	 * attempt will be made for VM_NORESERVE to allocate a page
#33 lore raw

PATCH 29/410 scsi: libsas: fix memory leak in sas_smp_get_phy_events()

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Jason Yan <[email protected]>

commit 4a491b1ab11ca0556d2fda1ff1301e862a2d44c4 upstream.

We've got a memory leak with the following producer:

while true;
do cat /sys/class/sas_phy/phy-1:0:12/invalid_dword_count >/dev/null; done

The buffer req is allocated and not freed after we return. Fix it.

Fixes 2908d778ab3e ("[SCSI] aic94xx: new driver")
CC John Garry <[email protected]>
CC chenqilin <[email protected]>
CC chenxiang <[email protected]>
---
 drivers/scsi/libsas/sas_expander.c | 1 +
 1 file changed, 1 insertion(+)
drivers/scsi/libsas/sas_expander.c +1 -0
@@ -684,6 +684,7 @@ int sas_smp_get_phy_events(struct sas_ph
 	phy->phy_reset_problem_count = scsi_to_u32(&resp[24]);
 
  out:
+	kfree(req);
 	kfree(resp);
 	return res;
 
#34 lore raw

PATCH 30/410 x86/MCE: Serialize sysfs changes

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Seunghun Han <[email protected]>

commit b3b7c4795ccab5be71f080774c45bbbcc75c2aaf upstream.

The check_interval file in

/sys/devices/system/machinecheck/machinecheck<cpu number>

directory is a global timer value for MCE polling. If it is changed by one CPU, mce_restart() broadcasts the event to other CPUs to delete and restart the MCE polling timer and __mcheck_cpu_init_timer() reinitializes the mce_timer variable.

If more than one CPU writes a specific value to the check_interval file concurrently, mce_timer is not protected from such concurrent accesses and all kinds of explosions happen. Since only root can write to those sysfs variables, the issue is not a big deal security-wise.

However, concurrent writes to these configuration variables is void of reason so the proper thing to do is to serialize the access with a mutex.

Boris:

- Make store_int_with_restart() use device_store_ulong() to filter out negative intervals
- Limit min interval to 1 second
- Correct locking
- Massage commit message

---
 arch/x86/kernel/cpu/mcheck/mce.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

--
To unsubscribe from this list: send the line "unsubscribe linux-edac" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

arch/x86/kernel/cpu/mcheck/mce.c +21 -1
@@ -57,6 +57,9 @@ static DEFINE_MUTEX(mce_chrdev_read_mute
 			      rcu_read_lock_sched_held() || \
 			      lockdep_is_held(&mce_chrdev_read_mutex))
 
+/* sysfs synchronization */
+static DEFINE_MUTEX(mce_sysfs_mutex);
+
 #define CREATE_TRACE_POINTS
 #include <trace/events/mce.h>
 
@@ -2199,6 +2202,7 @@ static ssize_t set_ignore_ce(struct devi
 	if (strict_strtoull(buf, 0, &new) < 0)
 		return -EINVAL;
 
+	mutex_lock(&mce_sysfs_mutex);
 	if (mca_cfg.ignore_ce ^ !!new) {
 		if (new) {
 			/* disable ce features */
@@ -2211,6 +2215,8 @@ static ssize_t set_ignore_ce(struct devi
 			on_each_cpu(mce_enable_ce, (void *)1, 1);
 		}
 	}
+	mutex_unlock(&mce_sysfs_mutex);
+
 	return size;
 }
 
@@ -2223,6 +2229,7 @@ static ssize_t set_cmci_disabled(struct
 	if (strict_strtoull(buf, 0, &new) < 0)
 		return -EINVAL;
 
+	mutex_lock(&mce_sysfs_mutex);
 	if (mca_cfg.cmci_disabled ^ !!new) {
 		if (new) {
 			/* disable cmci */
@@ -2234,6 +2241,8 @@ static ssize_t set_cmci_disabled(struct
 			on_each_cpu(mce_enable_ce, NULL, 1);
 		}
 	}
+	mutex_unlock(&mce_sysfs_mutex);
+
 	return size;
 }
 
@@ -2241,8 +2250,19 @@ static ssize_t store_int_with_restart(st
 				      struct device_attribute *attr,
 				      const char *buf, size_t size)
 {
-	ssize_t ret = device_store_int(s, attr, buf, size);
+	unsigned long old_check_interval = check_interval;
+	ssize_t ret = device_store_ulong(s, attr, buf, size);
+
+	if (check_interval == old_check_interval)
+		return ret;
+
+	if (check_interval < 1)
+		check_interval = 1;
+
+	mutex_lock(&mce_sysfs_mutex);
 	mce_restart();
+	mutex_unlock(&mce_sysfs_mutex);
+
 	return ret;
 }
 
#35 lore raw

PATCH 31/410 drm: udl: Properly check framebuffer mmap offsets

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Greg Kroah-Hartman <[email protected]>

commit 3b82a4db8eaccce735dffd50b4d4e1578099b8e8 upstream.

The memmap options sent to the udl framebuffer driver were not being checked for all sets of possible crazy values. Fix this up by properly bounding the allowed values.

---
 drivers/gpu/drm/udl/udl_fb.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/udl/udl_fb.c +7 -2
@@ -256,10 +256,15 @@ static int udl_fb_mmap(struct fb_info *i
 {
 	unsigned long start = vma->vm_start;
 	unsigned long size = vma->vm_end - vma->vm_start;
-	unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
+	unsigned long offset;
 	unsigned long page, pos;
 
-	if (offset + size > info->fix.smem_len)
+	if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
+		return -EINVAL;
+
+	offset = vma->vm_pgoff << PAGE_SHIFT;
+
+	if (offset > info->fix.smem_len || size > info->fix.smem_len - offset)
 		return -EINVAL;
 
 	pos = (unsigned long)info->fix.smem_start + offset;
#36 lore raw

PATCH 33/410 x86/traps: Enable DEBUG_STACK after cpu_init() for TRAP_DB/BP

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Wang Nan <[email protected]>

commit b4d8327024637cb2a1f7910dcb5d0ad7a096f473 upstream.

Before this patch early_trap_init() installs DEBUG_STACK for X86_TRAP_BP and X86_TRAP_DB. However, DEBUG_STACK doesn't work correctly until cpu_init() <-- trap_init().

This patch passes 0 to set_intr_gate_ist() and set_system_intr_gate_ist() instead of DEBUG_STACK to let it use same stack as kernel, and installs DEBUG_STACK for them in trap_init().

As core runs at ring 0 between early_trap_init() and trap_init(), there is no chance to get a bad stack before trap_init().

As NMI is also enabled in trap_init(), we don't need to care about is_debug_stack() and related things used in arch/x86/kernel/nmi.c.

---
 arch/x86/kernel/traps.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
arch/x86/kernel/traps.c +19 -2
@@ -773,9 +773,17 @@ dotraplinkage void do_iret_error(struct
 /* Set of traps needed for early debugging. */
 void __init early_trap_init(void)
 {
-	set_intr_gate_ist(X86_TRAP_DB, &debug, DEBUG_STACK);
+	/*
+	 * Don't set ist to DEBUG_STACK as it doesn't work until TSS is
+	 * ready in cpu_init() <-- trap_init(). Before trap_init(), CPU
+	 * runs at ring 0 so it is impossible to hit an invalid stack.
+	 * Using the original stack works well enough at this early
+	 * stage. DEBUG_STACK will be equipped after cpu_init() in
+	 * trap_init().
+	 */
+	set_intr_gate_ist(X86_TRAP_DB, &debug, 0);
 	/* int3 can be called from all */
-	set_system_intr_gate_ist(X86_TRAP_BP, &int3, DEBUG_STACK);
+	set_system_intr_gate_ist(X86_TRAP_BP, &int3, 0);
 #ifdef CONFIG_X86_32
 	set_intr_gate(X86_TRAP_PF, page_fault);
 #endif
@@ -853,6 +861,15 @@ void __init trap_init(void)
 	 */
 	cpu_init();
 
+	/*
+	 * X86_TRAP_DB and X86_TRAP_BP have been set
+	 * in early_trap_init(). However, DEBUG_STACK works only after
+	 * cpu_init() loads TSS. See comments in early_trap_init().
+	 */
+	set_intr_gate_ist(X86_TRAP_DB, &debug, DEBUG_STACK);
+	/* int3 can be called from all */
+	set_system_intr_gate_ist(X86_TRAP_BP, &int3, DEBUG_STACK);
+
 	x86_init.irqs.trap_init();
 
 #ifdef CONFIG_X86_64
#37 lore raw

PATCH 34/410 x86/entry/64: Don't use IST entry for #BP stack

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Andy Lutomirski <[email protected]>

commit d8ba61ba58c88d5207c1ba2f7d9a2280e7d03be9 upstream.

There's nothing IST-worthy about #BP/int3. We don't allow kprobes in the small handful of places in the kernel that run at CPL0 with an invalid stack, and 32-bit kernels have used normal interrupt gates for #BP forever.

Furthermore, we don't allow kprobes in places that have usergs while in kernel mode, so "paranoid" is also unnecessary.

[carnil: Backport to 3.16:
- Adjust finename change: arch/x86/kernel/entry_64.S
- Context changes
]
[bwh: Rebase on top of "x86/traps: Enable DEBUG_STACK after cpu_init() for
TRAP_DB/BP", and restore change in trap_init() instead of early_trap_init()]

---

arch/x86/kernel/entry_64.S +1 -1
@@ -1322,7 +1322,7 @@ apicinterrupt3 HYPERVISOR_CALLBACK_VECTO
 #endif /* CONFIG_HYPERV */
 
 idtentry debug do_debug has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK
-idtentry int3 do_int3 has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK
+idtentry int3 do_int3 has_error_code=0
 idtentry stack_segment do_stack_segment has_error_code=1
 #ifdef CONFIG_XEN
 idtentry xen_debug do_debug has_error_code=0
arch/x86/kernel/traps.c +3 -13
@@ -334,7 +334,6 @@ exit:
 }
 NOKPROBE_SYMBOL(do_general_protection);
 
-/* May run on IST stack. */
 dotraplinkage void notrace do_int3(struct pt_regs *regs, long error_code)
 {
 	enum ctx_state prev_state;
@@ -367,15 +366,9 @@ dotraplinkage void notrace do_int3(struc
 			SIGTRAP) == NOTIFY_STOP)
 		goto exit;
 
-	/*
-	 * Let others (NMI) know that the debug stack is in use
-	 * as we may switch to the interrupt stack.
-	 */
-	debug_stack_usage_inc();
 	preempt_conditional_sti(regs);
 	do_trap(X86_TRAP_BP, SIGTRAP, "int3", regs, error_code, NULL);
 	preempt_conditional_cli(regs);
-	debug_stack_usage_dec();
 exit:
 	exception_exit(prev_state);
 }
@@ -862,19 +855,16 @@ void __init trap_init(void)
 	cpu_init();
 
 	/*
-	 * X86_TRAP_DB and X86_TRAP_BP have been set
-	 * in early_trap_init(). However, DEBUG_STACK works only after
-	 * cpu_init() loads TSS. See comments in early_trap_init().
+	 * X86_TRAP_DB was installed in early_trap_init(). However,
+	 * DEBUG_STACK works only after cpu_init() loads TSS. See comments
+	 * in early_trap_init().
 	 */
 	set_intr_gate_ist(X86_TRAP_DB, &debug, DEBUG_STACK);
-	/* int3 can be called from all */
-	set_system_intr_gate_ist(X86_TRAP_BP, &int3, DEBUG_STACK);
 
 	x86_init.irqs.trap_init();
 
 #ifdef CONFIG_X86_64
 	memcpy(&debug_idt_table, &idt_table, IDT_ENTRIES * 16);
 	set_nmi_gate(X86_TRAP_DB, &debug);
-	set_nmi_gate(X86_TRAP_BP, &int3);
 #endif
 }
#38 lore raw

PATCH 35/410 cdrom: information leak in cdrom_ioctl_media_changed()

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Dan Carpenter <[email protected]>

commit 9de4ee40547fd315d4a0ed1dd15a2fa3559ad707 upstream.

This cast is wrong. "cdi->capacity" is an int and "arg" is an unsigned long. The way the check is written now, if one of the high 32 bits is set then we could read outside the info->slots[] array.

This bug is pretty old and it predates git.

---
 drivers/cdrom/cdrom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cdrom/cdrom.c +1 -1
@@ -2357,7 +2357,7 @@ static int cdrom_ioctl_media_changed(str
 	if (!CDROM_CAN(CDC_SELECT_DISC) || arg == CDSL_CURRENT)
 		return media_changed(cdi, 1);
 
-	if ((unsigned int)arg >= cdi->capacity)
+	if (arg >= cdi->capacity)
 		return -EINVAL;
 
 	info = kmalloc(sizeof(*info), GFP_KERNEL);
#39 lore raw

PATCH 36/410 perf/hwbp: Simplify the perf-hwbp code, fix documentation

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Linus Torvalds <[email protected]>

commit f67b15037a7a50c57f72e69a6d59941ad90a0f0f upstream.

Annoyingly, modify_user_hw_breakpoint() unnecessarily complicates the modification of a breakpoint - simplify it and remove the pointless local variables.

Also update the stale Docbook while at it.

Cc Alexander Shishkin <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Vince Weaver <[email protected]>
---
 kernel/events/hw_breakpoint.c | 30 +++++++-----------------------
 1 file changed, 7 insertions(+), 23 deletions(-)
kernel/events/hw_breakpoint.c +7 -23
@@ -427,16 +427,9 @@ EXPORT_SYMBOL_GPL(register_user_hw_break
  * modify_user_hw_breakpoint - modify a user-space hardware breakpoint
  * @bp: the breakpoint structure to modify
  * @attr: new breakpoint attributes
- * @triggered: callback to trigger when we hit the breakpoint
- * @tsk: pointer to 'task_struct' of the process to which the address belongs
  */
 int modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *attr)
 {
-	u64 old_addr = bp->attr.bp_addr;
-	u64 old_len = bp->attr.bp_len;
-	int old_type = bp->attr.bp_type;
-	int err = 0;
-
 	/*
 	 * modify_user_hw_breakpoint can be invoked with IRQs disabled and hence it
 	 * will not be possible to raise IPIs that invoke __perf_event_disable.
@@ -451,27 +444,18 @@ int modify_user_hw_breakpoint(struct per
 	bp->attr.bp_addr = attr->bp_addr;
 	bp->attr.bp_type = attr->bp_type;
 	bp->attr.bp_len = attr->bp_len;
+	bp->attr.disabled = 1;
 
-	if (attr->disabled)
-		goto end;
-
-	err = validate_hw_breakpoint(bp);
-	if (!err)
-		perf_event_enable(bp);
+	if (!attr->disabled) {
+		int err = validate_hw_breakpoint(bp);
 
-	if (err) {
-		bp->attr.bp_addr = old_addr;
-		bp->attr.bp_type = old_type;
-		bp->attr.bp_len = old_len;
-		if (!bp->attr.disabled)
-			perf_event_enable(bp);
+		if (err)
+			return err;
 
-		return err;
+		perf_event_enable(bp);
+		bp->attr.disabled = 0;
 	}
 
-end:
-	bp->attr.disabled = attr->disabled;
-
 	return 0;
 }
 EXPORT_SYMBOL_GPL(modify_user_hw_breakpoint);
#40 lore raw

PATCH 37/410 KVM: x86: rename update_db_bp_intercept to update_bp_intercept

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Paolo Bonzini <[email protected]>

commit a96036b8ef7df9f10cd575c0d78359bd33188e8e upstream.

Because #DB is now intercepted unconditionally, this callback only operates on #BP for both VMX and SVM.

[carnil: Backported to 3.16: adjust context]
---
 arch/x86/include/asm/kvm_host.h | 2 +-
 arch/x86/kvm/svm.c              | 2 +-
 arch/x86/kvm/vmx.c              | 2 +-
 arch/x86/kvm/x86.c              | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -1
@@ -682,7 +682,7 @@ struct kvm_x86_ops {
 	void (*vcpu_load)(struct kvm_vcpu *vcpu, int cpu);
 	void (*vcpu_put)(struct kvm_vcpu *vcpu);
 
-	void (*update_db_bp_intercept)(struct kvm_vcpu *vcpu);
+	void (*update_bp_intercept)(struct kvm_vcpu *vcpu);
 	int (*get_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata);
 	int (*set_msr)(struct kvm_vcpu *vcpu, struct msr_data *msr);
 	u64 (*get_segment_base)(struct kvm_vcpu *vcpu, int seg);
arch/x86/kvm/svm.c +1 -1
@@ -4353,7 +4353,7 @@ static struct kvm_x86_ops svm_x86_ops =
 	.vcpu_load = svm_vcpu_load,
 	.vcpu_put = svm_vcpu_put,
 
-	.update_db_bp_intercept = update_bp_intercept,
+	.update_bp_intercept = update_bp_intercept,
 	.get_msr = svm_get_msr,
 	.set_msr = svm_set_msr,
 	.get_segment_base = svm_get_segment_base,
arch/x86/kvm/vmx.c +1 -1
@@ -8932,7 +8932,7 @@ static struct kvm_x86_ops vmx_x86_ops =
 	.vcpu_load = vmx_vcpu_load,
 	.vcpu_put = vmx_vcpu_put,
 
-	.update_db_bp_intercept = update_exception_bitmap,
+	.update_bp_intercept = update_exception_bitmap,
 	.get_msr = vmx_get_msr,
 	.set_msr = vmx_set_msr,
 	.get_segment_base = vmx_get_segment_base,
arch/x86/kvm/x86.c +1 -1
@@ -6732,7 +6732,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(
 	 */
 	kvm_set_rflags(vcpu, rflags);
 
-	kvm_x86_ops->update_db_bp_intercept(vcpu);
+	kvm_x86_ops->update_bp_intercept(vcpu);
 
 	r = 0;
 
#41 lore raw

PATCH 38/410 KVM: x86: pass host_initiated to functions that read MSRs

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Paolo Bonzini <[email protected]>

commit 609e36d372ad9329269e4a1467bd35311893d1d6 upstream.

SMBASE is only readable from SMM for the VCPU, but it must be always accessible if userspace is accessing it. Thus, all functions that read MSRs are changed to accept a struct msr_data; the host_initiated and index fields are pre-initialized, while the data field is filled on return.

[carnil: backport to 3.16, adjust context]
[bwh: Adjust context again after update to 3.16.51]
---
 arch/x86/include/asm/kvm_host.h |   6 +-
 arch/x86/kvm/svm.c              |  52 ++++++++--------
 arch/x86/kvm/vmx.c              |  51 +++++++--------
 arch/x86/kvm/x86.c              | 106 ++++++++++++++++++++------------
 4 files changed, 118 insertions(+), 97 deletions(-)
arch/x86/include/asm/kvm_host.h +3 -3
@@ -683,7 +683,7 @@ struct kvm_x86_ops {
 	void (*vcpu_put)(struct kvm_vcpu *vcpu);
 
 	void (*update_bp_intercept)(struct kvm_vcpu *vcpu);
-	int (*get_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata);
+	int (*get_msr)(struct kvm_vcpu *vcpu, struct msr_data *msr);
 	int (*set_msr)(struct kvm_vcpu *vcpu, struct msr_data *msr);
 	u64 (*get_segment_base)(struct kvm_vcpu *vcpu, int seg);
 	void (*get_segment)(struct kvm_vcpu *vcpu,
@@ -853,7 +853,7 @@ static inline int emulate_instruction(st
 
 void kvm_enable_efer_bits(u64);
 bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer);
-int kvm_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *data);
+int kvm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr);
 int kvm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr);
 
 struct x86_emulate_ctxt;
@@ -881,7 +881,7 @@ void kvm_lmsw(struct kvm_vcpu *vcpu, uns
 void kvm_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l);
 int kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr);
 
-int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata);
+int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr);
 int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr);
 
 unsigned long kvm_get_rflags(struct kvm_vcpu *vcpu);
arch/x86/kvm/svm.c +27 -25

116 lines not on this page · raw message

arch/x86/kvm/vmx.c +23 -28

113 lines not on this page · raw message

arch/x86/kvm/x86.c +65 -41

234 lines not on this page · raw message

#42 lore raw

PATCH 39/410 x86/cpu: Rename "WESTMERE2" family to "NEHALEM_G"

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Dave Hansen <[email protected]>

commit 4b3b234f434d440fcd749b9636131b76e2ce561e upstream.

Len Brown noticed something was amiss in our INTEL_FAM6_* definitions. It seems like model 0x1F was a Nehalem part, marketed as "Intel Core i7 and i5 Processors" (according to the SDM). But, although it was a Nehalem 0x1F had some uncore events which were shared with Westmere.

Len also mentioned he thought it was called "Havendale", which Wikipedia says was graphics-oriented and canceled:

https://en.wikipedia.org/wiki/Nehalem_(microarchitecture)

So either way, it's probably not imporant what we call it, but call it Nehalem to be accurate, and add a "G" since it seems graphics-related. If it were canceled that would be a good reason why it's so sparsely and inconsistently referred to in the code.

Cc Dave Hansen <[email protected]>
Cc Len Brown <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
[bwh: Backported to 3.16: drop changes in intel_idle.c]
---
 arch/x86/include/asm/intel-family.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/intel-family.h +1 -1
@@ -18,10 +18,10 @@
 #define INTEL_FAM6_CORE2_DUNNINGTON	0x1D
 
 #define INTEL_FAM6_NEHALEM		0x1E
+#define INTEL_FAM6_NEHALEM_G		0x1F /* Auburndale / Havendale */
 #define INTEL_FAM6_NEHALEM_EP		0x1A
 #define INTEL_FAM6_NEHALEM_EX		0x2E
 #define INTEL_FAM6_WESTMERE		0x25
-#define INTEL_FAM6_WESTMERE2		0x1F
 #define INTEL_FAM6_WESTMERE_EP		0x2C
 #define INTEL_FAM6_WESTMERE_EX		0x2F
 
#43 lore raw

PATCH 40/410 x86/cpu: Rename Merrifield2 to Moorefield

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Andy Shevchenko <[email protected]>

commit f5fbf848303c8704d0e1a1e7cabd08fd0a49552f upstream.

Merrifield2 is actually Moorefield.

Rename it accordingly and drop tail digit from Merrifield1.

Cc Dave Hansen <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
[bwh: Backported to 3.16: Drop driver changes]
---
 arch/x86/include/asm/intel-family.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/intel-family.h +2 -2
@@ -56,8 +56,8 @@
 #define INTEL_FAM6_ATOM_SILVERMONT1	0x37 /* BayTrail/BYT / Valleyview */
 #define INTEL_FAM6_ATOM_SILVERMONT2	0x4D /* Avaton/Rangely */
 #define INTEL_FAM6_ATOM_AIRMONT		0x4C /* CherryTrail / Braswell */
-#define INTEL_FAM6_ATOM_MERRIFIELD1	0x4A /* Tangier */
-#define INTEL_FAM6_ATOM_MERRIFIELD2	0x5A /* Annidale */
+#define INTEL_FAM6_ATOM_MERRIFIELD	0x4A /* Tangier */
+#define INTEL_FAM6_ATOM_MOOREFIELD	0x5A /* Annidale */
 #define INTEL_FAM6_ATOM_GOLDMONT	0x5C
 #define INTEL_FAM6_ATOM_DENVERTON	0x5F /* Goldmont Microserver */
 
#44 lore raw

PATCH 41/410 x86/cpufeatures: Add Intel feature bits for Speculation Control

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: David Woodhouse <[email protected]>

commit fc67dd70adb711a45d2ef34e12d1a8be75edde61 upstream.

Add three feature bits exposed by new microcode on Intel CPUs for speculation control.

[bwh: Backported to 3.16: This CPUID word wasn't used at all yet, so
add it as feature word 10]

---
 arch/x86/include/asm/cpufeature.h | 7 ++++++-
 arch/x86/kernel/cpu/common.c      | 1 +
 2 files changed, 7 insertions(+), 1 deletion(-)
arch/x86/include/asm/cpufeature.h +6 -1
@@ -8,7 +8,7 @@
 #include <asm/required-features.h>
 #endif
 
-#define NCAPINTS	10	/* N 32-bit words worth of info */
+#define NCAPINTS	11	/* N 32-bit words worth of info */
 #define NBUGINTS	1	/* N 32-bit bug flags */
 
 /*
@@ -234,6 +234,11 @@
 #define X86_FEATURE_AVX512ER	(9*32+27) /* AVX-512 Exponential and Reciprocal */
 #define X86_FEATURE_AVX512CD	(9*32+28) /* AVX-512 Conflict Detection */
 
+/* Intel-defined CPU features, CPUID level 0x00000007:0 (EDX), word 10 */
+#define X86_FEATURE_SPEC_CTRL		(10*32+26) /* Speculation Control (IBRS + IBPB) */
+#define X86_FEATURE_STIBP		(10*32+27) /* Single Thread Indirect Branch Predictors */
+#define X86_FEATURE_ARCH_CAPABILITIES	(10*32+29) /* IA32_ARCH_CAPABILITIES MSR (Intel) */
+
 /*
  * BUG word(s)
  */
arch/x86/kernel/cpu/common.c +1 -0
@@ -701,6 +701,7 @@ void get_cpu_cap(struct cpuinfo_x86 *c)
 		cpuid_count(0x00000007, 0, &eax, &ebx, &ecx, &edx);
 
 		c->x86_capability[9] = ebx;
+		c->x86_capability[10] = edx;
 	}
 
 	/* AMD-defined flags: level 0x80000001 */
#45 lore raw

PATCH 42/410 x86/cpufeatures: Add AMD feature bits for Speculation Control

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: David Woodhouse <[email protected]>

commit 5d10cbc91d9eb5537998b65608441b592eec65e7 upstream.

AMD exposes the PRED_CMD/SPEC_CTRL MSRs slightly differently to Intel. See http://lkml.kernel.org/r/[email protected]

[bwh: Backported to 3.16: This CPUID word wasn't used at all yet, so
add it as feature word 11]

---
 arch/x86/include/asm/cpufeature.h | 7 ++++++-
 arch/x86/kernel/cpu/common.c      | 5 ++++-
 2 files changed, 10 insertions(+), 2 deletions(-)
arch/x86/include/asm/cpufeature.h +6 -1
@@ -8,7 +8,7 @@
 #include <asm/required-features.h>
 #endif
 
-#define NCAPINTS	11	/* N 32-bit words worth of info */
+#define NCAPINTS	12	/* N 32-bit words worth of info */
 #define NBUGINTS	1	/* N 32-bit bug flags */
 
 /*
@@ -239,6 +239,11 @@
 #define X86_FEATURE_STIBP		(10*32+27) /* Single Thread Indirect Branch Predictors */
 #define X86_FEATURE_ARCH_CAPABILITIES	(10*32+29) /* IA32_ARCH_CAPABILITIES MSR (Intel) */
 
+/* AMD-defined CPU features, CPUID level 0x80000008 (EBX), word 11 */
+#define X86_FEATURE_AMD_PRED_CMD	(11*32+12) /* Prediction Command MSR (AMD) */
+#define X86_FEATURE_AMD_SPEC_CTRL	(11*32+14) /* Speculation Control MSR only (AMD) */
+#define X86_FEATURE_AMD_STIBP		(11*32+15) /* Single Thread Indirect Branch Predictors (AMD) */
+
 /*
  * BUG word(s)
  */
arch/x86/kernel/cpu/common.c +4 -1
@@ -716,10 +716,13 @@ void get_cpu_cap(struct cpuinfo_x86 *c)
 	}
 
 	if (c->extended_cpuid_level >= 0x80000008) {
-		u32 eax = cpuid_eax(0x80000008);
+		u32 eax, ebx, ecx, edx;
+
+		cpuid(0x80000008, &eax, &ebx, &ecx, &edx);
 
 		c->x86_virt_bits = (eax >> 8) & 0xff;
 		c->x86_phys_bits = eax & 0xff;
+		c->x86_capability[11] = ebx;
 	}
 #ifdef CONFIG_X86_32
 	else if (cpu_has(c, X86_FEATURE_PAE) || cpu_has(c, X86_FEATURE_PSE36))
#46 lore raw

PATCH 43/410 x86/msr: Add definitions for new speculation control MSRs

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: David Woodhouse <[email protected]>

commit 1e340c60d0dd3ae07b5bedc16a0469c14b9f3410 upstream.

Add MSR and bit definitions for SPEC_CTRL, PRED_CMD and ARCH_CAPABILITIES.

See Intel's 336996-Speculative-Execution-Side-Channel-Mitigations.pdf

---
 arch/x86/include/uapi/asm/msr-index.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/x86/include/uapi/asm/msr-index.h +12 -0
@@ -32,6 +32,13 @@
 #define EFER_FFXSR		(1<<_EFER_FFXSR)
 
 /* Intel MSRs. Some also available on other CPUs */
+#define MSR_IA32_SPEC_CTRL		0x00000048 /* Speculation Control */
+#define SPEC_CTRL_IBRS			(1 << 0)   /* Indirect Branch Restricted Speculation */
+#define SPEC_CTRL_STIBP			(1 << 1)   /* Single Thread Indirect Branch Predictors */
+
+#define MSR_IA32_PRED_CMD		0x00000049 /* Prediction Command */
+#define PRED_CMD_IBPB			(1 << 0)   /* Indirect Branch Prediction Barrier */
+
 #define MSR_IA32_PERFCTR0		0x000000c1
 #define MSR_IA32_PERFCTR1		0x000000c2
 #define MSR_FSB_FREQ			0x000000cd
@@ -46,6 +53,11 @@
 
 #define MSR_PLATFORM_INFO		0x000000ce
 #define MSR_MTRRcap			0x000000fe
+
+#define MSR_IA32_ARCH_CAPABILITIES	0x0000010a
+#define ARCH_CAP_RDCL_NO		(1 << 0)   /* Not susceptible to Meltdown */
+#define ARCH_CAP_IBRS_ALL		(1 << 1)   /* Enhanced IBRS support */
+
 #define MSR_IA32_BBL_CR_CTL		0x00000119
 #define MSR_IA32_BBL_CR_CTL3		0x0000011e
 
#47 lore raw

PATCH 44/410 x86/pti: Do not enable PTI on CPUs which are not vulnerable to Meltdown

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: David Woodhouse <[email protected]>

commit fec9434a12f38d3aeafeb75711b71d8a1fdef621 upstream.

Also, for CPUs which don't speculate at all, don't report that they're vulnerable to the Spectre variants either.

Leave the cpu_no_meltdown[] match table with just X86_VENDOR_AMD in it for now, even though that could be done with a simple comparison, on the assumption that we'll have more to add.

Based on suggestions from Dave Hansen and Alan Cox.

---
 arch/x86/kernel/cpu/common.c | 48 ++++++++++++++++++++++++++++++++----
 1 file changed, 43 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/common.c +43 -5
@@ -41,6 +41,8 @@
 #include <asm/pat.h>
 #include <asm/microcode.h>
 #include <asm/microcode_intel.h>
+#include <asm/intel-family.h>
+#include <asm/cpu_device_id.h>
 
 #ifdef CONFIG_X86_LOCAL_APIC
 #include <asm/uv/uv.h>
@@ -761,6 +763,41 @@ static void identify_cpu_without_cpuid(s
 #endif
 }
 
+static const __initdata struct x86_cpu_id cpu_no_speculation[] = {
+	{ X86_VENDOR_INTEL,	6, INTEL_FAM6_ATOM_CEDARVIEW,	X86_FEATURE_ANY },
+	{ X86_VENDOR_INTEL,	6, INTEL_FAM6_ATOM_CLOVERVIEW,	X86_FEATURE_ANY },
+	{ X86_VENDOR_INTEL,	6, INTEL_FAM6_ATOM_LINCROFT,	X86_FEATURE_ANY },
+	{ X86_VENDOR_INTEL,	6, INTEL_FAM6_ATOM_PENWELL,	X86_FEATURE_ANY },
+	{ X86_VENDOR_INTEL,	6, INTEL_FAM6_ATOM_PINEVIEW,	X86_FEATURE_ANY },
+	{ X86_VENDOR_CENTAUR,	5 },
+	{ X86_VENDOR_INTEL,	5 },
+	{ X86_VENDOR_NSC,	5 },
+	{ X86_VENDOR_ANY,	4 },
+	{}
+};
+
+static const __initdata struct x86_cpu_id cpu_no_meltdown[] = {
+	{ X86_VENDOR_AMD },
+	{}
+};
+
+static bool __init cpu_vulnerable_to_meltdown(struct cpuinfo_x86 *c)
+{
+	u64 ia32_cap = 0;
+
+	if (x86_match_cpu(cpu_no_meltdown))
+		return false;
+
+	if (cpu_has(c, X86_FEATURE_ARCH_CAPABILITIES))
+		rdmsrl(MSR_IA32_ARCH_CAPABILITIES, ia32_cap);
+
+	/* Rogue Data Cache Load? No! */
+	if (ia32_cap & ARCH_CAP_RDCL_NO)
+		return false;
+
+	return true;
+}
+
 /*
  * Do minimum CPU detection early.
  * Fields really needed: vendor, cpuid_level, family, model, mask,
@@ -809,11 +846,12 @@ static void __init early_identify_cpu(st
 
 	setup_force_cpu_cap(X86_FEATURE_ALWAYS);
 
-	if (c->x86_vendor != X86_VENDOR_AMD)
-		setup_force_cpu_bug(X86_BUG_CPU_MELTDOWN);
-
-	setup_force_cpu_bug(X86_BUG_SPECTRE_V1);
-	setup_force_cpu_bug(X86_BUG_SPECTRE_V2);
+	if (!x86_match_cpu(cpu_no_speculation)) {
+		if (cpu_vulnerable_to_meltdown(c))
+			setup_force_cpu_bug(X86_BUG_CPU_MELTDOWN);
+		setup_force_cpu_bug(X86_BUG_SPECTRE_V1);
+		setup_force_cpu_bug(X86_BUG_SPECTRE_V2);
+	}
 }
 
 void __init early_cpu_init(void)
#48 lore raw

PATCH 45/410 x86/pti: Mark constant arrays as __initconst

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Arnd Bergmann <[email protected]>

commit 4bf5d56d429cbc96c23d809a08f63cd29e1a702e upstream.

I'm seeing build failures from the two newly introduced arrays that are marked 'const' and '__initdata', which are mutually exclusive:

arch/x86/kernel/cpu/common.c:882:43: error: 'cpu_no_speculation' causes a section type conflict with 'e820_table_firmware_init' arch/x86/kernel/cpu/common.c:895:43: error: 'cpu_no_meltdown' causes a section type conflict with 'e820_table_firmware_init'

The correct annotation is __initconst.

Fixes fec9434a12f3 ("x86/pti: Do not enable PTI on CPUs which are not vulnerable to Meltdown")
Cc Ricardo Neri <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Thomas Garnier <[email protected]>
Cc David Woodhouse <[email protected]>
---
 arch/x86/kernel/cpu/common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/common.c +2 -2
@@ -763,7 +763,7 @@ static void identify_cpu_without_cpuid(s
 #endif
 }
 
-static const __initdata struct x86_cpu_id cpu_no_speculation[] = {
+static const __initconst struct x86_cpu_id cpu_no_speculation[] = {
 	{ X86_VENDOR_INTEL,	6, INTEL_FAM6_ATOM_CEDARVIEW,	X86_FEATURE_ANY },
 	{ X86_VENDOR_INTEL,	6, INTEL_FAM6_ATOM_CLOVERVIEW,	X86_FEATURE_ANY },
 	{ X86_VENDOR_INTEL,	6, INTEL_FAM6_ATOM_LINCROFT,	X86_FEATURE_ANY },
@@ -776,7 +776,7 @@ static const __initdata struct x86_cpu_i
 	{}
 };
 
-static const __initdata struct x86_cpu_id cpu_no_meltdown[] = {
+static const __initconst struct x86_cpu_id cpu_no_meltdown[] = {
 	{ X86_VENDOR_AMD },
 	{}
 };
#49 lore raw

PATCH 46/410 x86/cpufeature: Blacklist SPEC_CTRL/PRED_CMD on early Spectre v2 microcodes

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: David Woodhouse <[email protected]>

commit a5b2966364538a0e68c9fa29bc0a3a1651799035 upstream.

This doesn't refuse to load the affected microcodes; it just refuses to use the Spectre v2 mitigation features if they're detected, by clearing the appropriate feature bits.

The AMD CPUID bits are handled here too, because hypervisors *may* have been exposing those bits even on Intel chips, for fine-grained control of what's available.

It is non-trivial to use x86_match_cpu() for this table because that doesn't handle steppings. And the approach taken in commit bd9240a18 almost made me lose my lunch.

---
 arch/x86/include/asm/intel-family.h |  7 ++-
 arch/x86/kernel/cpu/intel.c         | 67 +++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 2 deletions(-)
arch/x86/include/asm/intel-family.h +5 -2
@@ -12,6 +12,7 @@
  */
 
 #define INTEL_FAM6_CORE_YONAH		0x0E
+
 #define INTEL_FAM6_CORE2_MEROM		0x0F
 #define INTEL_FAM6_CORE2_MEROM_L	0x16
 #define INTEL_FAM6_CORE2_PENRYN		0x17
@@ -21,6 +22,7 @@
 #define INTEL_FAM6_NEHALEM_G		0x1F /* Auburndale / Havendale */
 #define INTEL_FAM6_NEHALEM_EP		0x1A
 #define INTEL_FAM6_NEHALEM_EX		0x2E
+
 #define INTEL_FAM6_WESTMERE		0x25
 #define INTEL_FAM6_WESTMERE_EP		0x2C
 #define INTEL_FAM6_WESTMERE_EX		0x2F
@@ -36,9 +38,9 @@
 #define INTEL_FAM6_HASWELL_GT3E		0x46
 
 #define INTEL_FAM6_BROADWELL_CORE	0x3D
-#define INTEL_FAM6_BROADWELL_XEON_D	0x56
 #define INTEL_FAM6_BROADWELL_GT3E	0x47
 #define INTEL_FAM6_BROADWELL_X		0x4F
+#define INTEL_FAM6_BROADWELL_XEON_D	0x56
 
 #define INTEL_FAM6_SKYLAKE_MOBILE	0x4E
 #define INTEL_FAM6_SKYLAKE_DESKTOP	0x5E
@@ -57,9 +59,10 @@
 #define INTEL_FAM6_ATOM_SILVERMONT2	0x4D /* Avaton/Rangely */
 #define INTEL_FAM6_ATOM_AIRMONT		0x4C /* CherryTrail / Braswell */
 #define INTEL_FAM6_ATOM_MERRIFIELD	0x4A /* Tangier */
-#define INTEL_FAM6_ATOM_MOOREFIELD	0x5A /* Annidale */
+#define INTEL_FAM6_ATOM_MOOREFIELD	0x5A /* Anniedale */
 #define INTEL_FAM6_ATOM_GOLDMONT	0x5C
 #define INTEL_FAM6_ATOM_DENVERTON	0x5F /* Goldmont Microserver */
+#define INTEL_FAM6_ATOM_GEMINI_LAKE	0x7A
 
 /* Xeon Phi */
 
arch/x86/kernel/cpu/intel.c +67 -0

85 lines not on this page · raw message

#50 lore raw

PATCH 47/410 x86/speculation: Add basic IBPB (Indirect Branch Prediction Barrier) support

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: David Woodhouse <[email protected]>

commit 20ffa1caecca4db8f79fe665acdeaa5af815a24d upstream.

Expose indirect_branch_prediction_barrier() for use in subsequent patches.

[ tglx: Add IBPB status to spectre_v2 sysfs file ]

[bwh: Backported to 3.16:
- Renumber the feature bit
- Adjust context]

---
 arch/x86/include/asm/cpufeature.h    |  2 ++
 arch/x86/include/asm/nospec-branch.h | 13 +++++++++++++
 arch/x86/kernel/cpu/bugs.c           | 10 +++++++++-
 3 files changed, 24 insertions(+), 1 deletion(-)
arch/x86/include/asm/cpufeature.h +2 -0
@@ -189,6 +189,8 @@
 #define X86_FEATURE_INVPCID_SINGLE (7*32+10) /* Effectively INVPCID && CR4.PCIDE=1 */
 #define X86_FEATURE_RSB_CTXSW	(7*32+11) /* "" Fill RSB on context switches */
 
+#define X86_FEATURE_IBPB	(7*32+12) /* Indirect Branch Prediction Barrier enabled*/
+
 #define X86_FEATURE_RETPOLINE	(7*32+29) /* "" Generic Retpoline mitigation for Spectre variant 2 */
 #define X86_FEATURE_RETPOLINE_AMD (7*32+30) /* "" AMD Retpoline mitigation for Spectre variant 2 */
 /* Because the ALTERNATIVE scheme is for members of the X86_FEATURE club... */
arch/x86/include/asm/nospec-branch.h +13 -0
@@ -194,5 +194,18 @@ static inline void vmexit_fill_RSB(void)
 #endif
 }
 
+static inline void indirect_branch_prediction_barrier(void)
+{
+	asm volatile(ALTERNATIVE("",
+				 "movl %[msr], %%ecx\n\t"
+				 "movl %[val], %%eax\n\t"
+				 "movl $0, %%edx\n\t"
+				 "wrmsr",
+				 X86_FEATURE_IBPB)
+		     : : [msr] "i" (MSR_IA32_PRED_CMD),
+			 [val] "i" (PRED_CMD_IBPB)
+		     : "eax", "ecx", "edx", "memory");
+}
+
 #endif /* __ASSEMBLY__ */
 #endif /* _ASM_X86_NOSPEC_BRANCH_H_ */
arch/x86/kernel/cpu/bugs.c +9 -1
@@ -358,6 +358,13 @@ retpoline_auto:
 		setup_force_cpu_cap(X86_FEATURE_RSB_CTXSW);
 		pr_info("Filling RSB on context switch\n");
 	}
+
+	/* Initialize Indirect Branch Prediction Barrier if supported */
+	if (boot_cpu_has(X86_FEATURE_SPEC_CTRL) ||
+	    boot_cpu_has(X86_FEATURE_AMD_PRED_CMD)) {
+		setup_force_cpu_cap(X86_FEATURE_IBPB);
+		pr_info("Enabling Indirect Branch Prediction Barrier\n");
+	}
 }
 
 #undef pr_fmt
@@ -387,7 +394,8 @@ ssize_t cpu_show_spectre_v2(struct devic
 	if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2))
 		return sprintf(buf, "Not affected\n");
 
-	return sprintf(buf, "%s%s\n", spectre_v2_strings[spectre_v2_enabled],
+	return sprintf(buf, "%s%s%s\n", spectre_v2_strings[spectre_v2_enabled],
+		       boot_cpu_has(X86_FEATURE_IBPB) ? ", IPBP" : "",
 		       spectre_v2_module_string());
 }
 #endif
#51 lore raw

PATCH 48/410 x86/cpufeatures: Clean up Spectre v2 related CPUID flags

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: David Woodhouse <[email protected]>

commit 2961298efe1ea1b6fc0d7ee8b76018fa6c0bcef2 upstream.

We want to expose the hardware features simply in /proc/cpuinfo as "ibrs", "ibpb" and "stibp". Since AMD has separate CPUID bits for those, use them as the user-visible bits.

When the Intel SPEC_CTRL bit is set which indicates both IBRS and IBPB capability, set those (AMD) bits accordingly. Likewise if the Intel STIBP bit is set, set the AMD STIBP that's used for the generic hardware capability.

Hide the rest from /proc/cpuinfo by putting "" in the comments. Including RETPOLINE and RETPOLINE_AMD which shouldn't be visible there. There are patches to make the sysfs vulnerabilities information non-readable by non-root, and the same should apply to all information about which mitigations are actually in use. Those *shouldn't* appear in /proc/cpuinfo.

The feature bit for whether IBPB is actually used, which is needed for ALTERNATIVEs, is renamed to X86_FEATURE_USE_IBPB.

---
 arch/x86/include/asm/cpufeature.h    | 12 +++++------
 arch/x86/include/asm/nospec-branch.h |  2 +-
 arch/x86/kernel/cpu/bugs.c           |  7 +++----
 arch/x86/kernel/cpu/intel.c          | 31 +++++++++++++++++++---------
 4 files changed, 31 insertions(+), 21 deletions(-)
arch/x86/include/asm/cpufeature.h +6 -6
@@ -189,7 +189,7 @@
 #define X86_FEATURE_INVPCID_SINGLE (7*32+10) /* Effectively INVPCID && CR4.PCIDE=1 */
 #define X86_FEATURE_RSB_CTXSW	(7*32+11) /* "" Fill RSB on context switches */
 
-#define X86_FEATURE_IBPB	(7*32+12) /* Indirect Branch Prediction Barrier enabled*/
+#define X86_FEATURE_USE_IBPB	(7*32+12) /* "" Indirect Branch Prediction Barrier enabled */
 
 #define X86_FEATURE_RETPOLINE	(7*32+29) /* "" Generic Retpoline mitigation for Spectre variant 2 */
 #define X86_FEATURE_RETPOLINE_AMD (7*32+30) /* "" AMD Retpoline mitigation for Spectre variant 2 */
@@ -237,14 +237,14 @@
 #define X86_FEATURE_AVX512CD	(9*32+28) /* AVX-512 Conflict Detection */
 
 /* Intel-defined CPU features, CPUID level 0x00000007:0 (EDX), word 10 */
-#define X86_FEATURE_SPEC_CTRL		(10*32+26) /* Speculation Control (IBRS + IBPB) */
-#define X86_FEATURE_STIBP		(10*32+27) /* Single Thread Indirect Branch Predictors */
+#define X86_FEATURE_SPEC_CTRL		(10*32+26) /* "" Speculation Control (IBRS + IBPB) */
+#define X86_FEATURE_INTEL_STIBP		(10*32+27) /* "" Single Thread Indirect Branch Predictors */
 #define X86_FEATURE_ARCH_CAPABILITIES	(10*32+29) /* IA32_ARCH_CAPABILITIES MSR (Intel) */
 
 /* AMD-defined CPU features, CPUID level 0x80000008 (EBX), word 11 */
-#define X86_FEATURE_AMD_PRED_CMD	(11*32+12) /* Prediction Command MSR (AMD) */
-#define X86_FEATURE_AMD_SPEC_CTRL	(11*32+14) /* Speculation Control MSR only (AMD) */
-#define X86_FEATURE_AMD_STIBP		(11*32+15) /* Single Thread Indirect Branch Predictors (AMD) */
+#define X86_FEATURE_IBPB		(11*32+12) /* Indirect Branch Prediction Barrier */
+#define X86_FEATURE_IBRS		(11*32+14) /* Indirect Branch Restricted Speculation */
+#define X86_FEATURE_STIBP		(11*32+15) /* Single Thread Indirect Branch Predictors */
 
 /*
  * BUG word(s)
arch/x86/include/asm/nospec-branch.h +1 -1
@@ -201,7 +201,7 @@ static inline void indirect_branch_predi
 				 "movl %[val], %%eax\n\t"
 				 "movl $0, %%edx\n\t"
 				 "wrmsr",
-				 X86_FEATURE_IBPB)
+				 X86_FEATURE_USE_IBPB)
 		     : : [msr] "i" (MSR_IA32_PRED_CMD),
 			 [val] "i" (PRED_CMD_IBPB)
 		     : "eax", "ecx", "edx", "memory");
arch/x86/kernel/cpu/bugs.c +3 -4
@@ -360,9 +360,8 @@ retpoline_auto:
 	}
 
 	/* Initialize Indirect Branch Prediction Barrier if supported */
-	if (boot_cpu_has(X86_FEATURE_SPEC_CTRL) ||
-	    boot_cpu_has(X86_FEATURE_AMD_PRED_CMD)) {
-		setup_force_cpu_cap(X86_FEATURE_IBPB);
+	if (boot_cpu_has(X86_FEATURE_IBPB)) {
+		setup_force_cpu_cap(X86_FEATURE_USE_IBPB);
 		pr_info("Enabling Indirect Branch Prediction Barrier\n");
 	}
 }
@@ -395,7 +394,7 @@ ssize_t cpu_show_spectre_v2(struct devic
 		return sprintf(buf, "Not affected\n");
 
 	return sprintf(buf, "%s%s%s\n", spectre_v2_strings[spectre_v2_enabled],
-		       boot_cpu_has(X86_FEATURE_IBPB) ? ", IPBP" : "",
+		       boot_cpu_has(X86_FEATURE_USE_IBPB) ? ", IBPB" : "",
 		       spectre_v2_module_string());
 }
 #endif
arch/x86/kernel/cpu/intel.c +21 -10
@@ -105,17 +105,28 @@ static void early_init_intel(struct cpui
 		rdmsr(MSR_IA32_UCODE_REV, lower_word, c->microcode);
 	}
 
-	if ((cpu_has(c, X86_FEATURE_SPEC_CTRL) ||
-	     cpu_has(c, X86_FEATURE_STIBP) ||
-	     cpu_has(c, X86_FEATURE_AMD_SPEC_CTRL) ||
-	     cpu_has(c, X86_FEATURE_AMD_PRED_CMD) ||
-	     cpu_has(c, X86_FEATURE_AMD_STIBP)) && bad_spectre_microcode(c)) {
-		pr_warn("Intel Spectre v2 broken microcode detected; disabling SPEC_CTRL\n");
-		clear_cpu_cap(c, X86_FEATURE_SPEC_CTRL);
+	/*
+	 * The Intel SPEC_CTRL CPUID bit implies IBRS and IBPB support,
+	 * and they also have a different bit for STIBP support. Also,
+	 * a hypervisor might have set the individual AMD bits even on
+	 * Intel CPUs, for finer-grained selection of what's available.
+	 */
+	if (cpu_has(c, X86_FEATURE_SPEC_CTRL)) {
+		set_cpu_cap(c, X86_FEATURE_IBRS);
+		set_cpu_cap(c, X86_FEATURE_IBPB);
+	}
+	if (cpu_has(c, X86_FEATURE_INTEL_STIBP))
+		set_cpu_cap(c, X86_FEATURE_STIBP);
+
+	/* Now if any of them are set, check the blacklist and clear the lot */
+	if ((cpu_has(c, X86_FEATURE_IBRS) || cpu_has(c, X86_FEATURE_IBPB) ||
+	     cpu_has(c, X86_FEATURE_STIBP)) && bad_spectre_microcode(c)) {
+		pr_warn("Intel Spectre v2 broken microcode detected; disabling Speculation Control\n");
+		clear_cpu_cap(c, X86_FEATURE_IBRS);
+		clear_cpu_cap(c, X86_FEATURE_IBPB);
 		clear_cpu_cap(c, X86_FEATURE_STIBP);
-		clear_cpu_cap(c, X86_FEATURE_AMD_SPEC_CTRL);
-		clear_cpu_cap(c, X86_FEATURE_AMD_PRED_CMD);
-		clear_cpu_cap(c, X86_FEATURE_AMD_STIBP);
+		clear_cpu_cap(c, X86_FEATURE_SPEC_CTRL);
+		clear_cpu_cap(c, X86_FEATURE_INTEL_STIBP);
 	}
 
 	/*
#52 lore raw

PATCH 49/410 x86/cpuid: Fix up "virtual" IBRS/IBPB/STIBP feature bits on Intel

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: David Woodhouse <[email protected]>

commit 7fcae1118f5fd44a862aa5c3525248e35ee67c3b upstream.

Despite the fact that all the other code there seems to be doing it, just using set_cpu_cap() in early_intel_init() doesn't actually work.

For CPUs with PKU support, setup_pku() calls get_cpu_cap() after c->c_init() has set those feature bits. That resets those bits back to what was queried from the hardware.

Turning the bits off for bad microcode is easy to fix. That can just use setup_clear_cpu_cap() to force them off for all CPUs.

I was less keen on forcing the feature bits *on* that way, just in case of inconsistencies. I appreciate that the kernel is going to get this utterly wrong if CPU features are not consistent, because it has already applied alternatives by the time secondary CPUs are brought up.

But at least if setup_force_cpu_cap() isn't being used, we might have a chance of *detecting* the lack of the corresponding bit and either panicking or refusing to bring the offending CPU online.

So ensure that the appropriate feature bits are set within get_cpu_cap() regardless of how many extra times it's called.

---
 arch/x86/kernel/cpu/common.c | 21 +++++++++++++++++++++
 arch/x86/kernel/cpu/intel.c  | 27 ++++++++-------------------
 2 files changed, 29 insertions(+), 19 deletions(-)
arch/x86/kernel/cpu/common.c +21 -0
@@ -682,6 +682,26 @@ static void apply_forced_caps(struct cpu
 	}
 }
 
+static void init_speculation_control(struct cpuinfo_x86 *c)
+{
+	/*
+	 * The Intel SPEC_CTRL CPUID bit implies IBRS and IBPB support,
+	 * and they also have a different bit for STIBP support. Also,
+	 * a hypervisor might have set the individual AMD bits even on
+	 * Intel CPUs, for finer-grained selection of what's available.
+	 *
+	 * We use the AMD bits in 0x8000_0008 EBX as the generic hardware
+	 * features, which are visible in /proc/cpuinfo and used by the
+	 * kernel. So set those accordingly from the Intel bits.
+	 */
+	if (cpu_has(c, X86_FEATURE_SPEC_CTRL)) {
+		set_cpu_cap(c, X86_FEATURE_IBRS);
+		set_cpu_cap(c, X86_FEATURE_IBPB);
+	}
+	if (cpu_has(c, X86_FEATURE_INTEL_STIBP))
+		set_cpu_cap(c, X86_FEATURE_STIBP);
+}
+
 void get_cpu_cap(struct cpuinfo_x86 *c)
 {
 	u32 tfms, xlvl;
@@ -735,6 +755,7 @@ void get_cpu_cap(struct cpuinfo_x86 *c)
 		c->x86_power = cpuid_edx(0x80000007);
 
 	init_scattered_cpuid_features(c);
+	init_speculation_control(c);
 }
 
 static void identify_cpu_without_cpuid(struct cpuinfo_x86 *c)
arch/x86/kernel/cpu/intel.c +8 -19
@@ -105,28 +105,17 @@ static void early_init_intel(struct cpui
 		rdmsr(MSR_IA32_UCODE_REV, lower_word, c->microcode);
 	}
 
-	/*
-	 * The Intel SPEC_CTRL CPUID bit implies IBRS and IBPB support,
-	 * and they also have a different bit for STIBP support. Also,
-	 * a hypervisor might have set the individual AMD bits even on
-	 * Intel CPUs, for finer-grained selection of what's available.
-	 */
-	if (cpu_has(c, X86_FEATURE_SPEC_CTRL)) {
-		set_cpu_cap(c, X86_FEATURE_IBRS);
-		set_cpu_cap(c, X86_FEATURE_IBPB);
-	}
-	if (cpu_has(c, X86_FEATURE_INTEL_STIBP))
-		set_cpu_cap(c, X86_FEATURE_STIBP);
-
 	/* Now if any of them are set, check the blacklist and clear the lot */
-	if ((cpu_has(c, X86_FEATURE_IBRS) || cpu_has(c, X86_FEATURE_IBPB) ||
+	if ((cpu_has(c, X86_FEATURE_SPEC_CTRL) ||
+	     cpu_has(c, X86_FEATURE_INTEL_STIBP) ||
+	     cpu_has(c, X86_FEATURE_IBRS) || cpu_has(c, X86_FEATURE_IBPB) ||
 	     cpu_has(c, X86_FEATURE_STIBP)) && bad_spectre_microcode(c)) {
 		pr_warn("Intel Spectre v2 broken microcode detected; disabling Speculation Control\n");
-		clear_cpu_cap(c, X86_FEATURE_IBRS);
-		clear_cpu_cap(c, X86_FEATURE_IBPB);
-		clear_cpu_cap(c, X86_FEATURE_STIBP);
-		clear_cpu_cap(c, X86_FEATURE_SPEC_CTRL);
-		clear_cpu_cap(c, X86_FEATURE_INTEL_STIBP);
+		setup_clear_cpu_cap(X86_FEATURE_IBRS);
+		setup_clear_cpu_cap(X86_FEATURE_IBPB);
+		setup_clear_cpu_cap(X86_FEATURE_STIBP);
+		setup_clear_cpu_cap(X86_FEATURE_SPEC_CTRL);
+		setup_clear_cpu_cap(X86_FEATURE_INTEL_STIBP);
 	}
 
 	/*
#53 lore raw

PATCH 50/410 x86/speculation: Use IBRS if available before calling into firmware

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: David Woodhouse <[email protected]>

commit dd84441a797150dcc49298ec95c459a8891d8bb1 upstream.

Retpoline means the kernel is safe because it has no indirect branches. But firmware isn't, so use IBRS for firmware calls if it's available.

Block preemption while IBRS is set, although in practice the call sites already had to be doing that.

Ignore hpwdt.c for now. It's taking spinlocks and calling into firmware code, from an NMI handler. I don't want to touch that with a bargepole.

[bwh: Backported to 3.16:
- x86 defines {,__}efi_call_virt() itself; update those definitions
- Renumber the feature bit
- Adjust context]

---
 arch/x86/include/asm/apm.h           |  6 +++++
 arch/x86/include/asm/cpufeature.h    |  1 +
 arch/x86/include/asm/efi.h           |  8 ++++++
 arch/x86/include/asm/nospec-branch.h | 39 +++++++++++++++++++++-------
 arch/x86/kernel/cpu/bugs.c           | 12 ++++++++-
 5 files changed, 56 insertions(+), 10 deletions(-)
arch/x86/include/asm/apm.h +6 -0
@@ -6,6 +6,8 @@
 #ifndef _ASM_X86_MACH_DEFAULT_APM_H
 #define _ASM_X86_MACH_DEFAULT_APM_H
 
+#include <asm/nospec-branch.h>
+
 #ifdef APM_ZERO_SEGS
 #	define APM_DO_ZERO_SEGS \
 		"pushl %%ds\n\t" \
@@ -31,6 +33,7 @@ static inline void apm_bios_call_asm(u32
 	 * N.B. We do NOT need a cld after the BIOS call
 	 * because we always save and restore the flags.
 	 */
+	firmware_restrict_branch_speculation_start();
 	__asm__ __volatile__(APM_DO_ZERO_SEGS
 		"pushl %%edi\n\t"
 		"pushl %%ebp\n\t"
@@ -43,6 +46,7 @@ static inline void apm_bios_call_asm(u32
 		  "=S" (*esi)
 		: "a" (func), "b" (ebx_in), "c" (ecx_in)
 		: "memory", "cc");
+	firmware_restrict_branch_speculation_end();
 }
 
 static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
@@ -55,6 +59,7 @@ static inline u8 apm_bios_call_simple_as
 	 * N.B. We do NOT need a cld after the BIOS call
 	 * because we always save and restore the flags.
 	 */
+	firmware_restrict_branch_speculation_start();
 	__asm__ __volatile__(APM_DO_ZERO_SEGS
 		"pushl %%edi\n\t"
 		"pushl %%ebp\n\t"
@@ -67,6 +72,7 @@ static inline u8 apm_bios_call_simple_as
 		  "=S" (si)
 		: "a" (func), "b" (ebx_in), "c" (ecx_in)
 		: "memory", "cc");
+	firmware_restrict_branch_speculation_end();
 	return error;
 }
 
arch/x86/include/asm/cpufeature.h +1 -0
@@ -190,6 +190,7 @@
 #define X86_FEATURE_RSB_CTXSW	(7*32+11) /* "" Fill RSB on context switches */
 
 #define X86_FEATURE_USE_IBPB	(7*32+12) /* "" Indirect Branch Prediction Barrier enabled */
+#define X86_FEATURE_USE_IBRS_FW (7*32+13) /* "" Use IBRS during runtime firmware calls */
 
 #define X86_FEATURE_RETPOLINE	(7*32+29) /* "" Generic Retpoline mitigation for Spectre variant 2 */
 #define X86_FEATURE_RETPOLINE_AMD (7*32+30) /* "" AMD Retpoline mitigation for Spectre variant 2 */
arch/x86/include/asm/efi.h +8 -0
@@ -2,6 +2,8 @@
 #define _ASM_X86_EFI_H
 
 #include <asm/i387.h>
+#include <asm/nospec-branch.h>
+
 /*
  * We map the EFI regions needed for runtime services non-contiguously,
  * with preserved alignment on virtual addresses starting from -4G down
@@ -37,8 +39,10 @@ extern unsigned long asmlinkage efi_call
 ({									\
 	efi_status_t __s;						\
 	kernel_fpu_begin();						\
+	firmware_restrict_branch_speculation_start();			\
 	__s = ((efi_##f##_t __attribute__((regparm(0)))*)		\
 		efi.systab->runtime->f)(args);				\
+	firmware_restrict_branch_speculation_end();			\
 	kernel_fpu_end();						\
 	__s;								\
 })
@@ -47,8 +51,10 @@ extern unsigned long asmlinkage efi_call
 #define __efi_call_virt(f, args...) \
 ({									\
 	kernel_fpu_begin();						\
+	firmware_restrict_branch_speculation_start();			\
 	((efi_##f##_t __attribute__((regparm(0)))*)			\
 		efi.systab->runtime->f)(args);				\
+	firmware_restrict_branch_speculation_end();			\
 	kernel_fpu_end();						\
 })
 
@@ -69,7 +75,9 @@ extern u64 asmlinkage efi_call(void *fp,
 	efi_sync_low_kernel_mappings();					\
 	preempt_disable();						\
 	__kernel_fpu_begin();						\
+	firmware_restrict_branch_speculation_start();			\
 	__s = efi_call((void *)efi.systab->runtime->f, __VA_ARGS__);	\
+	firmware_restrict_branch_speculation_end();			\
 	__kernel_fpu_end();						\
 	preempt_enable();						\
 	__s;								\
arch/x86/include/asm/nospec-branch.h +30 -9
@@ -194,17 +194,38 @@ static inline void vmexit_fill_RSB(void)
 #endif
 }
 
+#define alternative_msr_write(_msr, _val, _feature)		\
+	asm volatile(ALTERNATIVE("",				\
+				 "movl %[msr], %%ecx\n\t"	\
+				 "movl %[val], %%eax\n\t"	\
+				 "movl $0, %%edx\n\t"		\
+				 "wrmsr",			\
+				 _feature)			\
+		     : : [msr] "i" (_msr), [val] "i" (_val)	\
+		     : "eax", "ecx", "edx", "memory")
+
 static inline void indirect_branch_prediction_barrier(void)
 {
-	asm volatile(ALTERNATIVE("",
-				 "movl %[msr], %%ecx\n\t"
-				 "movl %[val], %%eax\n\t"
-				 "movl $0, %%edx\n\t"
-				 "wrmsr",
-				 X86_FEATURE_USE_IBPB)
-		     : : [msr] "i" (MSR_IA32_PRED_CMD),
-			 [val] "i" (PRED_CMD_IBPB)
-		     : "eax", "ecx", "edx", "memory");
+	alternative_msr_write(MSR_IA32_PRED_CMD, PRED_CMD_IBPB,
+			      X86_FEATURE_USE_IBPB);
+}
+
+/*
+ * With retpoline, we must use IBRS to restrict branch prediction
+ * before calling into firmware.
+ */
+static inline void firmware_restrict_branch_speculation_start(void)
+{
+	preempt_disable();
+	alternative_msr_write(MSR_IA32_SPEC_CTRL, SPEC_CTRL_IBRS,
+			      X86_FEATURE_USE_IBRS_FW);
+}
+
+static inline void firmware_restrict_branch_speculation_end(void)
+{
+	alternative_msr_write(MSR_IA32_SPEC_CTRL, 0,
+			      X86_FEATURE_USE_IBRS_FW);
+	preempt_enable();
 }
 
 #endif /* __ASSEMBLY__ */
arch/x86/kernel/cpu/bugs.c +11 -1
@@ -364,6 +364,15 @@ retpoline_auto:
 		setup_force_cpu_cap(X86_FEATURE_USE_IBPB);
 		pr_info("Enabling Indirect Branch Prediction Barrier\n");
 	}
+
+	/*
+	 * Retpoline means the kernel is safe because it has no indirect
+	 * branches. But firmware isn't, so use IBRS to protect that.
+	 */
+	if (boot_cpu_has(X86_FEATURE_IBRS)) {
+		setup_force_cpu_cap(X86_FEATURE_USE_IBRS_FW);
+		pr_info("Enabling Restricted Speculation for firmware calls\n");
+	}
 }
 
 #undef pr_fmt
@@ -393,8 +402,9 @@ ssize_t cpu_show_spectre_v2(struct devic
 	if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2))
 		return sprintf(buf, "Not affected\n");
 
-	return sprintf(buf, "%s%s%s\n", spectre_v2_strings[spectre_v2_enabled],
+	return sprintf(buf, "%s%s%s%s\n", spectre_v2_strings[spectre_v2_enabled],
 		       boot_cpu_has(X86_FEATURE_USE_IBPB) ? ", IBPB" : "",
+		       boot_cpu_has(X86_FEATURE_USE_IBRS_FW) ? ", IBRS_FW" : "",
 		       spectre_v2_module_string());
 }
 #endif
#54 lore raw

PATCH 51/410 KVM: nVMX: mark vmcs12 pages dirty on L2 exit

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: David Matlack <[email protected]>

commit c9f04407f2e0b3fc9ff7913c65fcfcb0a4b61570 upstream.

The host physical addresses of L1's Virtual APIC Page and Posted Interrupt descriptor are loaded into the VMCS02. The CPU may write to these pages via their host physical address while L2 is running, bypassing address-translation-based dirty tracking (e.g. EPT write protection). Mark them dirty on every exit from L2 to prevent them from getting out of sync with dirty tracking.

Also mark the virtual APIC page and the posted interrupt descriptor dirty when KVM is virtualizing posted interrupt processing.

[bwh: Backported to 3.16:
- No nested posted interrupt support
- No SMM support, so use mark_page_dirty() instead of kvm_vcpu_mark_page_dirty()]

---
 arch/x86/kvm/vmx.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
arch/x86/kvm/vmx.c +29 -0
@@ -4197,6 +4197,23 @@ static int vmx_vm_has_apicv(struct kvm *
 	return enable_apicv && irqchip_in_kernel(kvm);
 }
 
+static void nested_mark_vmcs12_pages_dirty(struct kvm_vcpu *vcpu)
+{
+	struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
+	gfn_t gfn;
+
+	/*
+	 * Don't need to mark the APIC access page dirty; it is never
+	 * written to by the CPU during APIC virtualization.
+	 */
+
+	if (nested_cpu_has(vmcs12, CPU_BASED_TPR_SHADOW)) {
+		gfn = vmcs12->virtual_apic_page_addr >> PAGE_SHIFT;
+		mark_page_dirty(vcpu->kvm, gfn);
+	}
+}
+
+
 /*
  * Send interrupt to vcpu via posted interrupt way.
  * 1. If target vcpu is running(non-root mode), send posted interrupt
@@ -6902,6 +6919,18 @@ static bool nested_vmx_exit_handled(stru
 				vmcs_read32(VM_EXIT_INTR_ERROR_CODE),
 				KVM_ISA_VMX);
 
+	/*
+	 * The host physical addresses of some pages of guest memory
+	 * are loaded into VMCS02 (e.g. L1's Virtual APIC Page). The CPU
+	 * may write to these pages via their host physical address while
+	 * L2 is running, bypassing any address-translation-based dirty
+	 * tracking (e.g. EPT write protection).
+	 *
+	 * Mark them dirty on every exit from L2 to prevent them from
+	 * getting out of sync with dirty tracking.
+	 */
+	nested_mark_vmcs12_pages_dirty(vcpu);
+
 	if (vmx->nested.nested_run_pending)
 		return 0;
 
#55 lore raw

PATCH 52/410 KVM: nVMX: Eliminate vmcs02 pool

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Jim Mattson <[email protected]>

commit de3a0021a60635de96aa92713c1a31a96747d72c upstream.

The potential performance advantages of a vmcs02 pool have never been realized. To simplify the code, eliminate the pool. Instead, a single vmcs02 is allocated per VCPU when the VCPU enters VMX operation.

[bwh: Backported to 3.16:
- No loaded_vmcs::shadow_vmcs field to initialise
- Adjust context]

---

arch/x86/kvm/vmx.c +22 -123
@@ -138,7 +138,6 @@ module_param(ple_window, int, S_IRUGO);
 extern const ulong vmx_return;
 
 #define NR_AUTOLOAD_MSRS 8
-#define VMCS02_POOL_SIZE 1
 
 struct vmcs {
 	u32 revision_id;
@@ -171,7 +170,7 @@ struct shared_msr_entry {
  * stored in guest memory specified by VMPTRLD, but is opaque to the guest,
  * which must access it using VMREAD/VMWRITE/VMCLEAR instructions.
  * More than one of these structures may exist, if L1 runs multiple L2 guests.
- * nested_vmx_run() will use the data here to build a vmcs02: a VMCS for the
+ * nested_vmx_run() will use the data here to build the vmcs02: a VMCS for the
  * underlying hardware which will be used to run L2.
  * This structure is packed to ensure that its layout is identical across
  * machines (necessary for live migration).
@@ -342,13 +341,6 @@ struct __packed vmcs12 {
  */
 #define VMCS12_SIZE 0x1000
 
-/* Used to remember the last vmcs02 used for some recently used vmcs12s */
-struct vmcs02_list {
-	struct list_head list;
-	gpa_t vmptr;
-	struct loaded_vmcs vmcs02;
-};
-
 /*
  * The nested_vmx structure is part of vcpu_vmx, and holds information we need
  * for correct emulation of VMX (i.e., nested VMX) on this vcpu.
@@ -370,16 +362,16 @@ struct nested_vmx {
 	 */
 	bool sync_shadow_vmcs;
 
-	/* vmcs02_list cache of VMCSs recently used to run L2 guests */
-	struct list_head vmcs02_pool;
-	int vmcs02_num;
 	u64 vmcs01_tsc_offset;
 	bool change_vmcs01_virtual_x2apic_mode;
 	/* L2 must run next, and mustn't decide to exit to L1. */
 	bool nested_run_pending;
+
+	struct loaded_vmcs vmcs02;
+
 	/*
-	 * Guest pages referred to in vmcs02 with host-physical pointers, so
-	 * we must keep them pinned while L2 runs.
+	 * Guest pages referred to in the vmcs02 with host-physical
+	 * pointers, so we must keep them pinned while L2 runs.
 	 */
 	struct page *apic_access_page;
 	u64 msr_ia32_feature_control;
@@ -5751,93 +5743,6 @@ static int handle_monitor(struct kvm_vcp
 }
 
 /*
- * To run an L2 guest, we need a vmcs02 based on the L1-specified vmcs12.
- * We could reuse a single VMCS for all the L2 guests, but we also want the
- * option to allocate a separate vmcs02 for each separate loaded vmcs12 - this
- * allows keeping them loaded on the processor, and in the future will allow
- * optimizations where prepare_vmcs02 doesn't need to set all the fields on
- * every entry if they never change.
- * So we keep, in vmx->nested.vmcs02_pool, a cache of size VMCS02_POOL_SIZE
- * (>=0) with a vmcs02 for each recently loaded vmcs12s, most recent first.
- *
- * The following functions allocate and free a vmcs02 in this pool.
- */
-
-/* Get a VMCS from the pool to use as vmcs02 for the current vmcs12. */
-static struct loaded_vmcs *nested_get_current_vmcs02(struct vcpu_vmx *vmx)
-{
-	struct vmcs02_list *item;
-	list_for_each_entry(item, &vmx->nested.vmcs02_pool, list)
-		if (item->vmptr == vmx->nested.current_vmptr) {
-			list_move(&item->list, &vmx->nested.vmcs02_pool);
-			return &item->vmcs02;
-		}
-
-	if (vmx->nested.vmcs02_num >= max(VMCS02_POOL_SIZE, 1)) {
-		/* Recycle the least recently used VMCS. */
-		item = list_entry(vmx->nested.vmcs02_pool.prev,
-			struct vmcs02_list, list);
-		item->vmptr = vmx->nested.current_vmptr;
-		list_move(&item->list, &vmx->nested.vmcs02_pool);
-		return &item->vmcs02;
-	}
-
-	/* Create a new VMCS */
-	item = kmalloc(sizeof(struct vmcs02_list), GFP_KERNEL);
-	if (!item)
-		return NULL;
-	item->vmcs02.vmcs = alloc_vmcs();
-	if (!item->vmcs02.vmcs) {
-		kfree(item);
-		return NULL;
-	}
-	loaded_vmcs_init(&item->vmcs02);
-	item->vmptr = vmx->nested.current_vmptr;
-	list_add(&(item->list), &(vmx->nested.vmcs02_pool));
-	vmx->nested.vmcs02_num++;
-	return &item->vmcs02;
-}
-
-/* Free and remove from pool a vmcs02 saved for a vmcs12 (if there is one) */
-static void nested_free_vmcs02(struct vcpu_vmx *vmx, gpa_t vmptr)
-{
-	struct vmcs02_list *item;
-	list_for_each_entry(item, &vmx->nested.vmcs02_pool, list)
-		if (item->vmptr == vmptr) {
-			free_loaded_vmcs(&item->vmcs02);
-			list_del(&item->list);
-			kfree(item);
-			vmx->nested.vmcs02_num--;
-			return;
-		}
-}
-
-/*
- * Free all VMCSs saved for this vcpu, except the one pointed by
- * vmx->loaded_vmcs. We must be running L1, so vmx->loaded_vmcs
- * must be &vmx->vmcs01.
- */
-static void nested_free_all_saved_vmcss(struct vcpu_vmx *vmx)
-{
-	struct vmcs02_list *item, *n;
-
-	WARN_ON(vmx->loaded_vmcs != &vmx->vmcs01);
-	list_for_each_entry_safe(item, n, &vmx->nested.vmcs02_pool, list) {
-		/*
-		 * Something will leak if the above WARN triggers.  Better than
-		 * a use-after-free.
-		 */
-		if (vmx->loaded_vmcs == &item->vmcs02)
-			continue;
-
-		free_loaded_vmcs(&item->vmcs02);
-		list_del(&item->list);
-		kfree(item);
-		vmx->nested.vmcs02_num--;
-	}
-}
-
-/*
  * The following 3 functions, nested_vmx_succeed()/failValid()/failInvalid(),
  * set the success or error code of an emulated VMX instruction, as specified
  * by Vol 2B, VMX Instruction Reference, "Conventions".
@@ -6099,10 +6004,17 @@ static int handle_vmon(struct kvm_vcpu *
 		return 1;
 	}
 
+	vmx->nested.vmcs02.vmcs = alloc_vmcs();
+	if (!vmx->nested.vmcs02.vmcs)
+		return -ENOMEM;
+	loaded_vmcs_init(&vmx->nested.vmcs02);
+
 	if (enable_shadow_vmcs) {
 		shadow_vmcs = alloc_vmcs();
-		if (!shadow_vmcs)
+		if (!shadow_vmcs) {
+			free_loaded_vmcs(&vmx->nested.vmcs02);
 			return -ENOMEM;
+		}
 		/* mark vmcs as shadow */
 		shadow_vmcs->revision_id |= (1u << 31);
 		/* init shadow vmcs */
@@ -6110,9 +6022,6 @@ static int handle_vmon(struct kvm_vcpu *
 		vmx->nested.current_shadow_vmcs = shadow_vmcs;
 	}
 
-	INIT_LIST_HEAD(&(vmx->nested.vmcs02_pool));
-	vmx->nested.vmcs02_num = 0;
-
 	hrtimer_init(&vmx->nested.preemption_timer, CLOCK_MONOTONIC,
 		     HRTIMER_MODE_REL);
 	vmx->nested.preemption_timer.function = vmx_preemption_timer_fn;
@@ -6189,13 +6098,13 @@ static void free_nested(struct vcpu_vmx
 	}
 	if (enable_shadow_vmcs)
 		free_vmcs(vmx->nested.current_shadow_vmcs);
-	/* Unpin physical memory we referred to in current vmcs02 */
+	/* Unpin physical memory we referred to in the vmcs02 */
 	if (vmx->nested.apic_access_page) {
 		nested_release_page(vmx->nested.apic_access_page);
 		vmx->nested.apic_access_page = 0;
 	}
 
-	nested_free_all_saved_vmcss(vmx);
+	free_loaded_vmcs(&vmx->nested.vmcs02);
 }
 
 /* Emulate the VMXOFF instruction */
@@ -6246,8 +6155,6 @@ static int handle_vmclear(struct kvm_vcp
 	kunmap(page);
 	nested_release_page(page);
 
-	nested_free_vmcs02(vmx, vmptr);
-
 	skip_emulated_instruction(vcpu);
 	nested_vmx_succeed(vcpu);
 	return 1;
@@ -6921,10 +6828,11 @@ static bool nested_vmx_exit_handled(stru
 
 	/*
 	 * The host physical addresses of some pages of guest memory
-	 * are loaded into VMCS02 (e.g. L1's Virtual APIC Page). The CPU
-	 * may write to these pages via their host physical address while
-	 * L2 is running, bypassing any address-translation-based dirty
-	 * tracking (e.g. EPT write protection).
+	 * are loaded into the vmcs02 (e.g. vmcs12's Virtual APIC
+	 * Page). The CPU may write to these pages via their host
+	 * physical address while L2 is running, bypassing any
+	 * address-translation-based dirty tracking (e.g. EPT write
+	 * protection).
 	 *
 	 * Mark them dirty on every exit from L2 to prevent them from
 	 * getting out of sync with dirty tracking.
@@ -8235,7 +8143,6 @@ static int nested_vmx_run(struct kvm_vcp
 	struct vmcs12 *vmcs12;
 	struct vcpu_vmx *vmx = to_vmx(vcpu);
 	int cpu;
-	struct loaded_vmcs *vmcs02;
 	bool ia32e;
 
 	if (!nested_vmx_check_permission(vcpu) ||
@@ -8372,16 +8279,12 @@ static int nested_vmx_run(struct kvm_vcp
 	 * the nested entry.
 	 */
 
-	vmcs02 = nested_get_current_vmcs02(vmx);
-	if (!vmcs02)
-		return -ENOMEM;
-
 	enter_guest_mode(vcpu);
 
 	vmx->nested.vmcs01_tsc_offset = vmcs_read64(TSC_OFFSET);
 
 	cpu = get_cpu();
-	vmx->loaded_vmcs = vmcs02;
+	vmx->loaded_vmcs = &vmx->nested.vmcs02;
 	vmx_vcpu_put(vcpu);
 	vmx_vcpu_load(vcpu, cpu);
 	vcpu->cpu = cpu;
@@ -8861,10 +8764,6 @@ static void nested_vmx_vmexit(struct kvm
 	vm_exit_controls_init(vmx, vmcs_read32(VM_EXIT_CONTROLS));
 	vmx_segment_cache_clear(vmx);
 
-	/* if no vmcs02 cache requested, remove the one we used */
-	if (VMCS02_POOL_SIZE == 0)
-		nested_free_vmcs02(vmx, vmx->nested.current_vmptr);
-
 	load_vmcs12_host_state(vcpu, vmcs12);
 
 	/* Update TSC_OFFSET if TSC was changed while L2 ran */
#56 lore raw

PATCH 53/410 KVM: VMX: introduce alloc_loaded_vmcs

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Paolo Bonzini <[email protected]>

commit f21f165ef922c2146cc5bdc620f542953c41714b upstream.

Group together the calls to alloc_vmcs and loaded_vmcs_init. Soon we'll also allocate an MSR bitmap there.

[bwh: Backported to 3.16:
- No loaded_vmcs::shadow_vmcs field to initialise
- Adjust context]

---

arch/x86/kvm/vmx.c +22 -13
@@ -2999,11 +2999,6 @@ static struct vmcs *alloc_vmcs_cpu(int c
 	return vmcs;
 }
 
-static struct vmcs *alloc_vmcs(void)
-{
-	return alloc_vmcs_cpu(raw_smp_processor_id());
-}
-
 static void free_vmcs(struct vmcs *vmcs)
 {
 	free_pages((unsigned long)vmcs, vmcs_config.order);
@@ -3021,6 +3016,21 @@ static void free_loaded_vmcs(struct load
 	loaded_vmcs->vmcs = NULL;
 }
 
+static struct vmcs *alloc_vmcs(void)
+{
+	return alloc_vmcs_cpu(raw_smp_processor_id());
+}
+
+static int alloc_loaded_vmcs(struct loaded_vmcs *loaded_vmcs)
+{
+	loaded_vmcs->vmcs = alloc_vmcs();
+	if (!loaded_vmcs->vmcs)
+		return -ENOMEM;
+
+	loaded_vmcs_init(loaded_vmcs);
+	return 0;
+}
+
 static void free_kvm_area(void)
 {
 	int cpu;
@@ -5965,6 +5975,7 @@ static int handle_vmon(struct kvm_vcpu *
 	struct vmcs *shadow_vmcs;
 	const u64 VMXON_NEEDED_FEATURES = FEATURE_CONTROL_LOCKED
 		| FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX;
+	int r;
 
 	/* The Intel VMX Instruction Reference lists a bunch of bits that
 	 * are prerequisite to running VMXON, most notably cr4.VMXE must be
@@ -6004,10 +6015,9 @@ static int handle_vmon(struct kvm_vcpu *
 		return 1;
 	}
 
-	vmx->nested.vmcs02.vmcs = alloc_vmcs();
-	if (!vmx->nested.vmcs02.vmcs)
+	r = alloc_loaded_vmcs(&vmx->nested.vmcs02);
+	if (r < 0)
 		return -ENOMEM;
-	loaded_vmcs_init(&vmx->nested.vmcs02);
 
 	if (enable_shadow_vmcs) {
 		shadow_vmcs = alloc_vmcs();
@@ -7612,16 +7622,15 @@ static struct kvm_vcpu *vmx_create_vcpu(
 		goto uninit_vcpu;
 	}
 
-	vmx->loaded_vmcs = &vmx->vmcs01;
-	vmx->loaded_vmcs->vmcs = alloc_vmcs();
-	if (!vmx->loaded_vmcs->vmcs)
-		goto free_msrs;
 	if (!vmm_exclusive)
 		kvm_cpu_vmxon(__pa(per_cpu(vmxarea, raw_smp_processor_id())));
-	loaded_vmcs_init(vmx->loaded_vmcs);
+	err = alloc_loaded_vmcs(&vmx->vmcs01);
 	if (!vmm_exclusive)
 		kvm_cpu_vmxoff();
+	if (err < 0)
+		goto free_msrs;
 
+	vmx->loaded_vmcs = &vmx->vmcs01;
 	cpu = get_cpu();
 	vmx_vcpu_load(&vmx->vcpu, cpu);
 	vmx->vcpu.cpu = cpu;
#57 lore raw

PATCH 54/410 KVM: VMX: make MSR bitmaps per-VCPU

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Paolo Bonzini <[email protected]>

commit 904e14fb7cb96401a7dc803ca2863fd5ba32ffe6 upstream.

Place the MSR bitmap in struct loaded_vmcs, and update it in place every time the x2apic or APICv state can change. This is rare and the loop can handle 64 MSRs per iteration, in a similar fashion as nested_vmx_prepare_msr_bitmap.

This prepares for choosing, on a per-VM basis, whether to intercept the SPEC_CTRL and PRED_CMD MSRs.

[bwh: Backported to 3.16:
- No support for nested MSR bitmaps
- APICv support looked different
- We still need to intercept the APIC_ID MSR
- Adjust context]

---
 arch/x86/kvm/vmx.c | 228 +++++++++++++++++++++------------------------
 1 file changed, 107 insertions(+), 121 deletions(-)
arch/x86/kvm/vmx.c +107 -121
@@ -101,6 +101,14 @@ module_param_named(enable_shadow_vmcs, e
 static bool __read_mostly nested = 0;
 module_param(nested, bool, S_IRUGO);
 
+#define MSR_TYPE_R	1
+#define MSR_TYPE_W	2
+#define MSR_TYPE_RW	3
+
+#define MSR_BITMAP_MODE_X2APIC		1
+#define MSR_BITMAP_MODE_X2APIC_APICV	2
+#define MSR_BITMAP_MODE_LM		4
+
 #define KVM_GUEST_CR0_MASK (X86_CR0_NW | X86_CR0_CD)
 #define KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST (X86_CR0_WP | X86_CR0_NE)
 #define KVM_VM_CR0_ALWAYS_ON						\
@@ -154,6 +162,7 @@ struct loaded_vmcs {
 	struct vmcs *vmcs;
 	int cpu;
 	int launched;
+	unsigned long *msr_bitmap;
 	struct list_head loaded_vmcss_on_cpu_link;
 };
 
@@ -410,6 +419,7 @@ struct vcpu_vmx {
 	unsigned long         host_rsp;
 	u8                    fail;
 	bool                  nmi_known_unmasked;
+	u8		      msr_bitmap_mode;
 	u32                   exit_intr_info;
 	u32                   idt_vectoring_info;
 	ulong                 rflags;
@@ -745,6 +755,7 @@ static void vmx_sync_pir_to_irr_dummy(st
 static void copy_vmcs12_to_shadow(struct vcpu_vmx *vmx);
 static void copy_shadow_to_vmcs12(struct vcpu_vmx *vmx);
 static bool vmx_mpx_supported(void);
+static void vmx_update_msr_bitmap(struct kvm_vcpu *vcpu);
 
 static DEFINE_PER_CPU(struct vmcs *, vmxarea);
 static DEFINE_PER_CPU(struct vmcs *, current_vmcs);
@@ -757,10 +768,6 @@ static DEFINE_PER_CPU(struct desc_ptr, h
 
 static unsigned long *vmx_io_bitmap_a;
 static unsigned long *vmx_io_bitmap_b;
-static unsigned long *vmx_msr_bitmap_legacy;
-static unsigned long *vmx_msr_bitmap_longmode;
-static unsigned long *vmx_msr_bitmap_legacy_x2apic;
-static unsigned long *vmx_msr_bitmap_longmode_x2apic;
 static unsigned long *vmx_vmread_bitmap;
 static unsigned long *vmx_vmwrite_bitmap;
 
@@ -2073,25 +2080,6 @@ static void move_msr_up(struct vcpu_vmx
 	vmx->guest_msrs[from] = tmp;
 }
 
-static void vmx_set_msr_bitmap(struct kvm_vcpu *vcpu)
-{
-	unsigned long *msr_bitmap;
-
-	if (irqchip_in_kernel(vcpu->kvm) && apic_x2apic_mode(vcpu->arch.apic)) {
-		if (is_long_mode(vcpu))
-			msr_bitmap = vmx_msr_bitmap_longmode_x2apic;
-		else
-			msr_bitmap = vmx_msr_bitmap_legacy_x2apic;
-	} else {
-		if (is_long_mode(vcpu))
-			msr_bitmap = vmx_msr_bitmap_longmode;
-		else
-			msr_bitmap = vmx_msr_bitmap_legacy;
-	}
-
-	vmcs_write64(MSR_BITMAP, __pa(msr_bitmap));
-}
-
 /*
  * Set up the vmcs to automatically save and restore system
  * msrs.  Don't touch the 64-bit msrs if the guest is in legacy
@@ -2132,7 +2120,7 @@ static void setup_msrs(struct vcpu_vmx *
 	vmx->save_nmsrs = save_nmsrs;
 
 	if (cpu_has_vmx_msr_bitmap())
-		vmx_set_msr_bitmap(&vmx->vcpu);
+		vmx_update_msr_bitmap(&vmx->vcpu);
 }
 
 /*
@@ -3014,6 +3002,8 @@ static void free_loaded_vmcs(struct load
 	loaded_vmcs_clear(loaded_vmcs);
 	free_vmcs(loaded_vmcs->vmcs);
 	loaded_vmcs->vmcs = NULL;
+	if (loaded_vmcs->msr_bitmap)
+		free_page((unsigned long)loaded_vmcs->msr_bitmap);
 }
 
 static struct vmcs *alloc_vmcs(void)
@@ -3028,7 +3018,18 @@ static int alloc_loaded_vmcs(struct load
 		return -ENOMEM;
 
 	loaded_vmcs_init(loaded_vmcs);
+
+	if (cpu_has_vmx_msr_bitmap()) {
+		loaded_vmcs->msr_bitmap = (unsigned long *)__get_free_page(GFP_KERNEL);
+		if (!loaded_vmcs->msr_bitmap)
+			goto out_vmcs;
+		memset(loaded_vmcs->msr_bitmap, 0xff, PAGE_SIZE);
+	}
 	return 0;
+
+out_vmcs:
+	free_loaded_vmcs(loaded_vmcs);
+	return -ENOMEM;
 }
 
 static void free_kvm_area(void)
@@ -4089,10 +4090,8 @@ static void free_vpid(struct vcpu_vmx *v
 	spin_unlock(&vmx_vpid_lock);
 }
 
-#define MSR_TYPE_R	1
-#define MSR_TYPE_W	2
-static void __vmx_disable_intercept_for_msr(unsigned long *msr_bitmap,
-						u32 msr, int type)
+static void __always_inline vmx_disable_intercept_for_msr(unsigned long *msr_bitmap,
+							  u32 msr, int type)
 {
 	int f = sizeof(unsigned long);
 
@@ -4126,8 +4125,8 @@ static void __vmx_disable_intercept_for_
 	}
 }
 
-static void __vmx_enable_intercept_for_msr(unsigned long *msr_bitmap,
-						u32 msr, int type)
+static void __always_inline vmx_enable_intercept_for_msr(unsigned long *msr_bitmap,
+							 u32 msr, int type)
 {
 	int f = sizeof(unsigned long);
 
@@ -4161,37 +4160,76 @@ static void __vmx_enable_intercept_for_m
 	}
 }
 
-static void vmx_disable_intercept_for_msr(u32 msr, bool longmode_only)
+static void __always_inline vmx_set_intercept_for_msr(unsigned long *msr_bitmap,
+			     			      u32 msr, int type, bool value)
 {
-	if (!longmode_only)
-		__vmx_disable_intercept_for_msr(vmx_msr_bitmap_legacy,
-						msr, MSR_TYPE_R | MSR_TYPE_W);
-	__vmx_disable_intercept_for_msr(vmx_msr_bitmap_longmode,
-						msr, MSR_TYPE_R | MSR_TYPE_W);
+	if (value)
+		vmx_enable_intercept_for_msr(msr_bitmap, msr, type);
+	else
+		vmx_disable_intercept_for_msr(msr_bitmap, msr, type);
 }
 
-static void vmx_enable_intercept_msr_read_x2apic(u32 msr)
+static u8 vmx_msr_bitmap_mode(struct kvm_vcpu *vcpu)
 {
-	__vmx_enable_intercept_for_msr(vmx_msr_bitmap_legacy_x2apic,
-			msr, MSR_TYPE_R);
-	__vmx_enable_intercept_for_msr(vmx_msr_bitmap_longmode_x2apic,
-			msr, MSR_TYPE_R);
+	u8 mode = 0;
+
+	if (irqchip_in_kernel(vcpu->kvm) && apic_x2apic_mode(vcpu->arch.apic)) {
+		mode |= MSR_BITMAP_MODE_X2APIC;
+		if (enable_apicv)
+			mode |= MSR_BITMAP_MODE_X2APIC_APICV;
+	}
+
+	if (is_long_mode(vcpu))
+		mode |= MSR_BITMAP_MODE_LM;
+
+	return mode;
 }
 
-static void vmx_disable_intercept_msr_read_x2apic(u32 msr)
+#define X2APIC_MSR(r) (APIC_BASE_MSR + ((r) >> 4))
+
+static void vmx_update_msr_bitmap_x2apic(unsigned long *msr_bitmap,
+					 u8 mode)
 {
-	__vmx_disable_intercept_for_msr(vmx_msr_bitmap_legacy_x2apic,
-			msr, MSR_TYPE_R);
-	__vmx_disable_intercept_for_msr(vmx_msr_bitmap_longmode_x2apic,
-			msr, MSR_TYPE_R);
+	int msr;
+
+	for (msr = 0x800; msr <= 0x8ff; msr += BITS_PER_LONG) {
+		unsigned word = msr / BITS_PER_LONG;
+		msr_bitmap[word] = (mode & MSR_BITMAP_MODE_X2APIC_APICV) ? 0 : ~0;
+		msr_bitmap[word + (0x800 / sizeof(long))] = ~0;
+	}
+
+	if (mode & MSR_BITMAP_MODE_X2APIC) {
+		/*
+		 * TPR reads and writes can be virtualized even if virtual interrupt
+		 * delivery is not in use.
+		 */
+		vmx_disable_intercept_for_msr(msr_bitmap, X2APIC_MSR(APIC_TASKPRI), MSR_TYPE_RW);
+		if (mode & MSR_BITMAP_MODE_X2APIC_APICV) {
+			vmx_enable_intercept_for_msr(msr_bitmap, X2APIC_MSR(APIC_ID), MSR_TYPE_R);
+			vmx_enable_intercept_for_msr(msr_bitmap, X2APIC_MSR(APIC_TMCCT), MSR_TYPE_R);
+			vmx_disable_intercept_for_msr(msr_bitmap, X2APIC_MSR(APIC_EOI), MSR_TYPE_W);
+			vmx_disable_intercept_for_msr(msr_bitmap, X2APIC_MSR(APIC_SELF_IPI), MSR_TYPE_W);
+		}
+	}
 }
 
-static void vmx_disable_intercept_msr_write_x2apic(u32 msr)
+static void vmx_update_msr_bitmap(struct kvm_vcpu *vcpu)
 {
-	__vmx_disable_intercept_for_msr(vmx_msr_bitmap_legacy_x2apic,
-			msr, MSR_TYPE_W);
-	__vmx_disable_intercept_for_msr(vmx_msr_bitmap_longmode_x2apic,
-			msr, MSR_TYPE_W);
+	struct vcpu_vmx *vmx = to_vmx(vcpu);
+	unsigned long *msr_bitmap = vmx->vmcs01.msr_bitmap;
+	u8 mode = vmx_msr_bitmap_mode(vcpu);
+	u8 changed = mode ^ vmx->msr_bitmap_mode;
+
+	if (!changed)
+		return;
+
+	vmx_set_intercept_for_msr(msr_bitmap, MSR_KERNEL_GS_BASE, MSR_TYPE_RW,
+				  !(mode & MSR_BITMAP_MODE_LM));
+
+	if (changed & (MSR_BITMAP_MODE_X2APIC | MSR_BITMAP_MODE_X2APIC_APICV))
+		vmx_update_msr_bitmap_x2apic(msr_bitmap, mode);
+
+	vmx->msr_bitmap_mode = mode;
 }
 
 static int vmx_vm_has_apicv(struct kvm *kvm)
@@ -4412,7 +4450,7 @@ static int vmx_vcpu_setup(struct vcpu_vm
 		vmcs_write64(VMWRITE_BITMAP, __pa(vmx_vmwrite_bitmap));
 	}
 	if (cpu_has_vmx_msr_bitmap())
-		vmcs_write64(MSR_BITMAP, __pa(vmx_msr_bitmap_legacy));
+		vmcs_write64(MSR_BITMAP, __pa(vmx->vmcs01.msr_bitmap));
 
 	vmcs_write64(VMCS_LINK_POINTER, -1ull); /* 22.3.1.5 */
 
@@ -7085,7 +7123,7 @@ static void vmx_set_virtual_x2apic_mode(
 	}
 	vmcs_write32(SECONDARY_VM_EXEC_CONTROL, sec_exec_control);
 
-	vmx_set_msr_bitmap(vcpu);
+	vmx_update_msr_bitmap(vcpu);
 }
 
 static void vmx_hwapic_isr_update(struct kvm *kvm, int isr)
@@ -7605,6 +7643,7 @@ static struct kvm_vcpu *vmx_create_vcpu(
 {
 	int err;
 	struct vcpu_vmx *vmx = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL);
+	unsigned long *msr_bitmap;
 	int cpu;
 
 	if (!vmx)
@@ -7630,6 +7669,15 @@ static struct kvm_vcpu *vmx_create_vcpu(
 	if (err < 0)
 		goto free_msrs;
 
+	msr_bitmap = vmx->vmcs01.msr_bitmap;
+	vmx_disable_intercept_for_msr(msr_bitmap, MSR_FS_BASE, MSR_TYPE_RW);
+	vmx_disable_intercept_for_msr(msr_bitmap, MSR_GS_BASE, MSR_TYPE_RW);
+	vmx_disable_intercept_for_msr(msr_bitmap, MSR_KERNEL_GS_BASE, MSR_TYPE_RW);
+	vmx_disable_intercept_for_msr(msr_bitmap, MSR_IA32_SYSENTER_CS, MSR_TYPE_RW);
+	vmx_disable_intercept_for_msr(msr_bitmap, MSR_IA32_SYSENTER_ESP, MSR_TYPE_RW);
+	vmx_disable_intercept_for_msr(msr_bitmap, MSR_IA32_SYSENTER_EIP, MSR_TYPE_RW);
+	vmx->msr_bitmap_mode = 0;
+
 	vmx->loaded_vmcs = &vmx->vmcs01;
 	cpu = get_cpu();
 	vmx_vcpu_load(&vmx->vcpu, cpu);
@@ -8955,7 +9003,7 @@ static struct kvm_x86_ops vmx_x86_ops =
 
 static int __init vmx_init(void)
 {
-	int r, i, msr;
+	int r, i;
 
 	rdmsrl_safe(MSR_EFER, &host_efer);
 
@@ -8972,30 +9020,13 @@ static int __init vmx_init(void)
 	if (!vmx_io_bitmap_b)
 		goto out;
 
-	vmx_msr_bitmap_legacy = (unsigned long *)__get_free_page(GFP_KERNEL);
-	if (!vmx_msr_bitmap_legacy)
-		goto out1;
-
-	vmx_msr_bitmap_legacy_x2apic =
-				(unsigned long *)__get_free_page(GFP_KERNEL);
-	if (!vmx_msr_bitmap_legacy_x2apic)
-		goto out2;
-
-	vmx_msr_bitmap_longmode = (unsigned long *)__get_free_page(GFP_KERNEL);
-	if (!vmx_msr_bitmap_longmode)
-		goto out3;
-
-	vmx_msr_bitmap_longmode_x2apic =
-				(unsigned long *)__get_free_page(GFP_KERNEL);
-	if (!vmx_msr_bitmap_longmode_x2apic)
-		goto out4;
 	vmx_vmread_bitmap = (unsigned long *)__get_free_page(GFP_KERNEL);
 	if (!vmx_vmread_bitmap)
-		goto out5;
+		goto out1;
 
 	vmx_vmwrite_bitmap = (unsigned long *)__get_free_page(GFP_KERNEL);
 	if (!vmx_vmwrite_bitmap)
-		goto out6;
+		goto out2;
 
 	memset(vmx_vmread_bitmap, 0xff, PAGE_SIZE);
 	memset(vmx_vmwrite_bitmap, 0xff, PAGE_SIZE);
@@ -9004,51 +9035,18 @@ static int __init vmx_init(void)
 
 	memset(vmx_io_bitmap_b, 0xff, PAGE_SIZE);
 
-	memset(vmx_msr_bitmap_legacy, 0xff, PAGE_SIZE);
-	memset(vmx_msr_bitmap_longmode, 0xff, PAGE_SIZE);
-
 	set_bit(0, vmx_vpid_bitmap); /* 0 is reserved for host */
 
 	r = kvm_init(&vmx_x86_ops, sizeof(struct vcpu_vmx),
 		     __alignof__(struct vcpu_vmx), THIS_MODULE);
 	if (r)
-		goto out7;
+		goto out3;
 
 #ifdef CONFIG_KEXEC
 	rcu_assign_pointer(crash_vmclear_loaded_vmcss,
 			   crash_vmclear_local_loaded_vmcss);
 #endif
 
-	vmx_disable_intercept_for_msr(MSR_FS_BASE, false);
-	vmx_disable_intercept_for_msr(MSR_GS_BASE, false);
-	vmx_disable_intercept_for_msr(MSR_KERNEL_GS_BASE, true);
-	vmx_disable_intercept_for_msr(MSR_IA32_SYSENTER_CS, false);
-	vmx_disable_intercept_for_msr(MSR_IA32_SYSENTER_ESP, false);
-	vmx_disable_intercept_for_msr(MSR_IA32_SYSENTER_EIP, false);
-
-	memcpy(vmx_msr_bitmap_legacy_x2apic,
-			vmx_msr_bitmap_legacy, PAGE_SIZE);
-	memcpy(vmx_msr_bitmap_longmode_x2apic,
-			vmx_msr_bitmap_longmode, PAGE_SIZE);
-
-	if (enable_apicv) {
-		for (msr = 0x800; msr <= 0x8ff; msr++)
-			vmx_disable_intercept_msr_read_x2apic(msr);
-
-		/* According SDM, in x2apic mode, the whole id reg is used.
-		 * But in KVM, it only use the highest eight bits. Need to
-		 * intercept it */
-		vmx_enable_intercept_msr_read_x2apic(0x802);
-		/* TMCCT */
-		vmx_enable_intercept_msr_read_x2apic(0x839);
-		/* TPR */
-		vmx_disable_intercept_msr_write_x2apic(0x808);
-		/* EOI */
-		vmx_disable_intercept_msr_write_x2apic(0x80b);
-		/* SELF-IPI */
-		vmx_disable_intercept_msr_write_x2apic(0x83f);
-	}
-
 	if (enable_ept) {
 		kvm_mmu_set_mask_ptes(0ull,
 			(enable_ept_ad_bits) ? VMX_EPT_ACCESS_BIT : 0ull,
@@ -9061,18 +9059,10 @@ static int __init vmx_init(void)
 
 	return 0;
 
-out7:
-	free_page((unsigned long)vmx_vmwrite_bitmap);
-out6:
-	free_page((unsigned long)vmx_vmread_bitmap);
-out5:
-	free_page((unsigned long)vmx_msr_bitmap_longmode_x2apic);
-out4:
-	free_page((unsigned long)vmx_msr_bitmap_longmode);
 out3:
-	free_page((unsigned long)vmx_msr_bitmap_legacy_x2apic);
+	free_page((unsigned long)vmx_vmwrite_bitmap);
 out2:
-	free_page((unsigned long)vmx_msr_bitmap_legacy);
+	free_page((unsigned long)vmx_vmread_bitmap);
 out1:
 	free_page((unsigned long)vmx_io_bitmap_b);
 out:
@@ -9082,10 +9072,6 @@ out:
 
 static void __exit vmx_exit(void)
 {
-	free_page((unsigned long)vmx_msr_bitmap_legacy_x2apic);
-	free_page((unsigned long)vmx_msr_bitmap_longmode_x2apic);
-	free_page((unsigned long)vmx_msr_bitmap_legacy);
-	free_page((unsigned long)vmx_msr_bitmap_longmode);
 	free_page((unsigned long)vmx_io_bitmap_b);
 	free_page((unsigned long)vmx_io_bitmap_a);
 	free_page((unsigned long)vmx_vmwrite_bitmap);
#58 lore raw

PATCH 55/410 KVM/x86: Add IBPB support

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Ashok Raj <[email protected]>

commit 15d45071523d89b3fb7372e2135fbd72f6af9506 upstream.

The Indirect Branch Predictor Barrier (IBPB) is an indirect branch control mechanism. It keeps earlier branches from influencing later ones.

Unlike IBRS and STIBP, IBPB does not define a new mode of operation. It's a command that ensures predicted branch targets aren't used after the barrier. Although IBRS and IBPB are enumerated by the same CPUID enumeration, IBPB is very different.

IBPB helps mitigate against three potential attacks:

* Mitigate guests from being attacked by other guests.
- This is addressed by issing IBPB when we do a guest switch.

* Mitigate attacks from guest/ring3->host/ring3.
These would require a IBPB during context switch in host, or after VMEXIT. The host process has two ways to mitigate
- Either it can be compiled with retpoline
- If its going through context switch, and has set !dumpable then there is a IBPB in that path.
(Tim's patch: https://patchwork.kernel.org/patch/10192871)
- The case where after a VMEXIT you return back to Qemu might make Qemu attackable from guest when Qemu isn't compiled with retpoline.
There are issues reported when doing IBPB on every VMEXIT that resulted in some tsc calibration woes in guest.

* Mitigate guest/ring0->host/ring0 attacks.
When host kernel is using retpoline it is safe against these attacks. If host kernel isn't using retpoline we might need to do a IBPB flush on every VMEXIT.

Even when using retpoline for indirect calls, in certain conditions 'ret' can use the BTB on Skylake-era CPUs. There are other mitigations available like RSB stuffing/clearing.

* IBPB is issued only for SVM during svm_free_vcpu(). VMX has a vmclear and SVM doesn't. Follow discussion here:
https://lkml.org/lkml/2018/1/15/146

Please refer to the following spec for more details on the enumeration and control.

Refer here to get documentation about mitigations.

https://software.intel.com/en-us/side-channel-security-support

[peterz: rebase and changelog rewrite]
[karahmed: - rebase
- vmx: expose PRED_CMD if guest has it in CPUID
- svm: only pass through IBPB if guest has it in CPUID
- vmx: support !cpu_has_vmx_msr_bitmap()]
- vmx: support nested]
[dwmw2: Expose CPUID bit too (AMD IBPB only for now as we lack IBRS)
PRED_CMD is a write-only MSR]

[bwh: Backported to 3.16:
- No support for nested MSR bitmaps in VMX
- Use literal number for CPU feature word
- Adjust context]

---
 arch/x86/kvm/cpuid.c | 11 ++++++++-
 arch/x86/kvm/cpuid.h | 12 ++++++++++
 arch/x86/kvm/svm.c   | 28 +++++++++++++++++++++++
 arch/x86/kvm/vmx.c   | 54 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 104 insertions(+), 1 deletion(-)
arch/x86/kvm/cpuid.c +10 -1
@@ -300,6 +300,10 @@ static inline int __do_cpuid_ent(struct
 		F(3DNOWPREFETCH) | F(OSVW) | 0 /* IBS */ | F(XOP) |
 		0 /* SKINIT, WDT, LWP */ | F(FMA4) | F(TBM);
 
+	/* cpuid 0x80000008.ebx */
+	const u32 kvm_cpuid_8000_0008_ebx_x86_features =
+		F(IBPB);
+
 	/* cpuid 0xC0000001.edx */
 	const u32 kvm_supported_word5_x86_features =
 		F(XSTORE) | F(XSTORE_EN) | F(XCRYPT) | F(XCRYPT_EN) |
@@ -512,7 +516,12 @@ static inline int __do_cpuid_ent(struct
 		if (!g_phys_as)
 			g_phys_as = phys_as;
 		entry->eax = g_phys_as | (virt_as << 8);
-		entry->ebx = entry->edx = 0;
+		entry->edx = 0;
+		/* IBPB isn't necessarily present in hardware cpuid */
+		if (boot_cpu_has(X86_FEATURE_IBPB))
+			entry->ebx |= F(IBPB);
+		entry->ebx &= kvm_cpuid_8000_0008_ebx_x86_features;
+		cpuid_mask(&entry->ebx, 11);
 		break;
 	}
 	case 0x80000019:
arch/x86/kvm/cpuid.h +12 -0
@@ -104,4 +104,16 @@ static inline bool guest_cpuid_has_mpx(s
 	return best && (best->ebx & bit(X86_FEATURE_MPX));
 }
 
+static inline bool guest_cpuid_has_ibpb(struct kvm_vcpu *vcpu)
+{
+	struct kvm_cpuid_entry2 *best;
+
+	best = kvm_find_cpuid_entry(vcpu, 0x80000008, 0);
+	if (best && (best->ebx & bit(X86_FEATURE_IBPB)))
+		return true;
+	best = kvm_find_cpuid_entry(vcpu, 7, 0);
+	return best && (best->edx & bit(X86_FEATURE_SPEC_CTRL));
+}
+
+
 #endif
arch/x86/kvm/svm.c +28 -0
@@ -180,6 +180,7 @@ static const struct svm_direct_access_ms
 	{ .index = MSR_CSTAR,				.always = true  },
 	{ .index = MSR_SYSCALL_MASK,			.always = true  },
 #endif
+	{ .index = MSR_IA32_PRED_CMD,			.always = false },
 	{ .index = MSR_IA32_LASTBRANCHFROMIP,		.always = false },
 	{ .index = MSR_IA32_LASTBRANCHTOIP,		.always = false },
 	{ .index = MSR_IA32_LASTINTFROMIP,		.always = false },
@@ -409,6 +410,7 @@ struct svm_cpu_data {
 	struct kvm_ldttss_desc *tss_desc;
 
 	struct page *save_area;
+	struct vmcb *current_vmcb;
 };
 
 static DEFINE_PER_CPU(struct svm_cpu_data *, svm_data);
@@ -1294,11 +1296,17 @@ static void svm_free_vcpu(struct kvm_vcp
 	__free_pages(virt_to_page(svm->nested.msrpm), MSRPM_ALLOC_ORDER);
 	kvm_vcpu_uninit(vcpu);
 	kmem_cache_free(kvm_vcpu_cache, svm);
+	/*
+	 * The vmcb page can be recycled, causing a false negative in
+	 * svm_vcpu_load(). So do a full IBPB now.
+	 */
+	indirect_branch_prediction_barrier();
 }
 
 static void svm_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 {
 	struct vcpu_svm *svm = to_svm(vcpu);
+	struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
 	int i;
 
 	if (unlikely(cpu != vcpu->cpu)) {
@@ -1321,6 +1329,10 @@ static void svm_vcpu_load(struct kvm_vcp
 		__get_cpu_var(current_tsc_ratio) = svm->tsc_ratio;
 		wrmsrl(MSR_AMD64_TSC_RATIO, svm->tsc_ratio);
 	}
+	if (sd->current_vmcb != svm->vmcb) {
+		sd->current_vmcb = svm->vmcb;
+		indirect_branch_prediction_barrier();
+	}
 }
 
 static void svm_vcpu_put(struct kvm_vcpu *vcpu)
@@ -3172,6 +3184,22 @@ static int svm_set_msr(struct kvm_vcpu *
 	case MSR_IA32_TSC:
 		kvm_write_tsc(vcpu, msr);
 		break;
+	case MSR_IA32_PRED_CMD:
+		if (!msr->host_initiated &&
+		    !guest_cpuid_has_ibpb(vcpu))
+			return 1;
+
+		if (data & ~PRED_CMD_IBPB)
+			return 1;
+
+		if (!data)
+			break;
+
+		wrmsrl(MSR_IA32_PRED_CMD, PRED_CMD_IBPB);
+		if (is_guest_mode(vcpu))
+			break;
+		set_msr_interception(svm->msrpm, MSR_IA32_PRED_CMD, 0, 1);
+		break;
 	case MSR_STAR:
 		svm->vmcb->save.star = data;
 		break;
arch/x86/kvm/vmx.c +54 -0

84 lines not on this page · raw message

#59 lore raw

PATCH 56/410 KVM/VMX: Emulate MSR_IA32_ARCH_CAPABILITIES

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: KarimAllah Ahmed <[email protected]>

commit 28c1c9fabf48d6ad596273a11c46e0d0da3e14cd upstream.

Intel processors use MSR_IA32_ARCH_CAPABILITIES MSR to indicate RDCL_NO (bit 0) and IBRS_ALL (bit 1). This is a read-only MSR. By default the contents will come directly from the hardware, but user-space can still override it.

[dwmw2: The bit in kvm_cpuid_7_0_edx_x86_features can be unconditional]

[bwh: Backported to 3.16:
- Add mapping of the relevant CPUID word
- Adjust context]

---
 arch/x86/kvm/cpuid.c | 11 +++++++++--
 arch/x86/kvm/cpuid.h |  8 ++++++++
 arch/x86/kvm/vmx.c   | 15 +++++++++++++++
 arch/x86/kvm/x86.c   |  3 ++-
 4 files changed, 34 insertions(+), 3 deletions(-)
arch/x86/kvm/cpuid.c +9 -2
@@ -316,6 +316,10 @@ static inline int __do_cpuid_ent(struct
 		F(BMI2) | F(ERMS) | f_invpcid | F(RTM) | f_mpx | F(RDSEED) |
 		F(ADX) | F(SMAP);
 
+	/* cpuid 7.0.edx*/
+	const u32 kvm_cpuid_7_0_edx_x86_features =
+		F(ARCH_CAPABILITIES);
+
 	/* all calls to cpuid_count() should be made on the same cpu */
 	get_cpu();
 
@@ -387,11 +391,14 @@ static inline int __do_cpuid_ent(struct
 			cpuid_mask(&entry->ebx, 9);
 			// TSC_ADJUST is emulated
 			entry->ebx |= F(TSC_ADJUST);
-		} else
+			entry->edx &= kvm_cpuid_7_0_edx_x86_features;
+			cpuid_mask(&entry->edx, 10);
+		} else {
 			entry->ebx = 0;
+			entry->edx = 0;
+		}
 		entry->eax = 0;
 		entry->ecx = 0;
-		entry->edx = 0;
 		break;
 	}
 	case 9:
arch/x86/kvm/cpuid.h +8 -0
@@ -115,5 +115,13 @@ static inline bool guest_cpuid_has_ibpb(
 	return best && (best->edx & bit(X86_FEATURE_SPEC_CTRL));
 }
 
+static inline bool guest_cpuid_has_arch_capabilities(struct kvm_vcpu *vcpu)
+{
+	struct kvm_cpuid_entry2 *best;
+
+	best = kvm_find_cpuid_entry(vcpu, 7, 0);
+	return best && (best->edx & bit(X86_FEATURE_ARCH_CAPABILITIES));
+}
+
 
 #endif
arch/x86/kvm/vmx.c +15 -0
@@ -432,6 +432,8 @@ struct vcpu_vmx {
 	u64 		      msr_guest_kernel_gs_base;
 #endif
 
+	u64 		      arch_capabilities;
+
 	u32 vm_entry_controls_shadow;
 	u32 vm_exit_controls_shadow;
 	/*
@@ -2522,6 +2524,12 @@ static int vmx_get_msr(struct kvm_vcpu *
 	case MSR_IA32_TSC:
 		msr_info->data = guest_read_tsc();
 		break;
+	case MSR_IA32_ARCH_CAPABILITIES:
+		if (!msr_info->host_initiated &&
+		    !guest_cpuid_has_arch_capabilities(vcpu))
+			return 1;
+		msr_info->data = to_vmx(vcpu)->arch_capabilities;
+		break;
 	case MSR_IA32_SYSENTER_CS:
 		msr_info->data = vmcs_read32(GUEST_SYSENTER_CS);
 		break;
@@ -2641,6 +2649,11 @@ static int vmx_set_msr(struct kvm_vcpu *
 		vmx_disable_intercept_for_msr(vmx->vmcs01.msr_bitmap, MSR_IA32_PRED_CMD,
 					      MSR_TYPE_W);
 		break;
+	case MSR_IA32_ARCH_CAPABILITIES:
+		if (!msr_info->host_initiated)
+			return 1;
+		vmx->arch_capabilities = data;
+		break;
 	case MSR_IA32_CR_PAT:
 		if (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_PAT) {
 			if (!kvm_mtrr_valid(vcpu, MSR_IA32_CR_PAT, data))
@@ -4584,6 +4597,8 @@ static int vmx_vcpu_setup(struct vcpu_vm
 		++vmx->nmsrs;
 	}
 
+	if (boot_cpu_has(X86_FEATURE_ARCH_CAPABILITIES))
+		rdmsrl(MSR_IA32_ARCH_CAPABILITIES, vmx->arch_capabilities);
 
 	vm_exit_controls_init(vmx, vmcs_config.vmexit_ctrl);
 
arch/x86/kvm/x86.c +2 -1
@@ -893,7 +893,8 @@ static u32 msrs_to_save[] = {
 	MSR_CSTAR, MSR_KERNEL_GS_BASE, MSR_SYSCALL_MASK, MSR_LSTAR,
 #endif
 	MSR_IA32_TSC, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA,
-	MSR_IA32_FEATURE_CONTROL, MSR_IA32_BNDCFGS
+	MSR_IA32_FEATURE_CONTROL, MSR_IA32_BNDCFGS,
+	MSR_IA32_ARCH_CAPABILITIES
 };
 
 static unsigned num_msrs_to_save;
#60 lore raw

PATCH 57/410 KVM/VMX: Allow direct access to MSR_IA32_SPEC_CTRL

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: KarimAllah Ahmed <[email protected]>

commit d28b387fb74da95d69d2615732f50cceb38e9a4d upstream.

[ Based on a patch from Ashok Raj <[email protected]> ]

Add direct access to MSR_IA32_SPEC_CTRL for guests. This is needed for guests that will only mitigate Spectre V2 through IBRS+IBPB and will not be using a retpoline+IBPB based approach.

To avoid the overhead of saving and restoring the MSR_IA32_SPEC_CTRL for guests that do not actually use the MSR, only start saving and restoring when a non-zero is written to it.

No attempt is made to handle STIBP here, intentionally. Filtering STIBP may be added in a future patch, which may require trapping all writes if we don't want to pass it through directly to the guest.

[dwmw2: Clean up CPUID bits, save/restore manually, handle reset]

[bwh: Backported to 3.16:
- No support for nested MSR bitmaps
- Adjust context]

---
 arch/x86/kvm/cpuid.c |  8 +++---
 arch/x86/kvm/cpuid.h | 11 ++++++++
 arch/x86/kvm/vmx.c   | 64 ++++++++++++++++++++++++++++++++++++++++++++
 arch/x86/kvm/x86.c   |  2 +-
 4 files changed, 81 insertions(+), 4 deletions(-)
arch/x86/kvm/cpuid.c +5 -3
@@ -302,7 +302,7 @@ static inline int __do_cpuid_ent(struct
 
 	/* cpuid 0x80000008.ebx */
 	const u32 kvm_cpuid_8000_0008_ebx_x86_features =
-		F(IBPB);
+		F(IBPB) | F(IBRS);
 
 	/* cpuid 0xC0000001.edx */
 	const u32 kvm_supported_word5_x86_features =
@@ -318,7 +318,7 @@ static inline int __do_cpuid_ent(struct
 
 	/* cpuid 7.0.edx*/
 	const u32 kvm_cpuid_7_0_edx_x86_features =
-		F(ARCH_CAPABILITIES);
+		F(SPEC_CTRL) | F(ARCH_CAPABILITIES);
 
 	/* all calls to cpuid_count() should be made on the same cpu */
 	get_cpu();
@@ -524,9 +524,11 @@ static inline int __do_cpuid_ent(struct
 			g_phys_as = phys_as;
 		entry->eax = g_phys_as | (virt_as << 8);
 		entry->edx = 0;
-		/* IBPB isn't necessarily present in hardware cpuid */
+		/* IBRS and IBPB aren't necessarily present in hardware cpuid */
 		if (boot_cpu_has(X86_FEATURE_IBPB))
 			entry->ebx |= F(IBPB);
+		if (boot_cpu_has(X86_FEATURE_IBRS))
+			entry->ebx |= F(IBRS);
 		entry->ebx &= kvm_cpuid_8000_0008_ebx_x86_features;
 		cpuid_mask(&entry->ebx, 11);
 		break;
arch/x86/kvm/cpuid.h +11 -0
@@ -115,6 +115,17 @@ static inline bool guest_cpuid_has_ibpb(
 	return best && (best->edx & bit(X86_FEATURE_SPEC_CTRL));
 }
 
+static inline bool guest_cpuid_has_ibrs(struct kvm_vcpu *vcpu)
+{
+	struct kvm_cpuid_entry2 *best;
+
+	best = kvm_find_cpuid_entry(vcpu, 0x80000008, 0);
+	if (best && (best->ebx & bit(X86_FEATURE_IBRS)))
+		return true;
+	best = kvm_find_cpuid_entry(vcpu, 7, 0);
+	return best && (best->edx & bit(X86_FEATURE_SPEC_CTRL));
+}
+
 static inline bool guest_cpuid_has_arch_capabilities(struct kvm_vcpu *vcpu)
 {
 	struct kvm_cpuid_entry2 *best;
arch/x86/kvm/vmx.c +64 -0

100 lines not on this page · raw message

arch/x86/kvm/x86.c +1 -1
@@ -894,7 +894,7 @@ static u32 msrs_to_save[] = {
 #endif
 	MSR_IA32_TSC, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA,
 	MSR_IA32_FEATURE_CONTROL, MSR_IA32_BNDCFGS,
-	MSR_IA32_ARCH_CAPABILITIES
+	MSR_IA32_SPEC_CTRL, MSR_IA32_ARCH_CAPABILITIES
 };
 
 static unsigned num_msrs_to_save;
#61 lore raw

PATCH 58/410 KVM/SVM: Allow direct access to MSR_IA32_SPEC_CTRL

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: KarimAllah Ahmed <[email protected]>

commit b2ac58f90540e39324e7a29a7ad471407ae0bf48 upstream.

[ Based on a patch from Paolo Bonzini <[email protected]> ]

... basically doing exactly what we do for VMX:

- Passthrough SPEC_CTRL to guests (if enabled in guest CPUID)
- Save and restore SPEC_CTRL around VMExit and VMEntry only if the guest actually used it.

---
 arch/x86/kvm/svm.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)
arch/x86/kvm/svm.c +88 -0
@@ -146,6 +146,8 @@ struct vcpu_svm {
 		u64 gs_base;
 	} host;
 
+	u64 spec_ctrl;
+
 	u32 *msrpm;
 
 	ulong nmi_iret_rip;
@@ -180,6 +182,7 @@ static const struct svm_direct_access_ms
 	{ .index = MSR_CSTAR,				.always = true  },
 	{ .index = MSR_SYSCALL_MASK,			.always = true  },
 #endif
+	{ .index = MSR_IA32_SPEC_CTRL,			.always = false },
 	{ .index = MSR_IA32_PRED_CMD,			.always = false },
 	{ .index = MSR_IA32_LASTBRANCHFROMIP,		.always = false },
 	{ .index = MSR_IA32_LASTBRANCHTOIP,		.always = false },
@@ -762,6 +765,25 @@ static bool valid_msr_intercept(u32 inde
 	return false;
 }
 
+static bool msr_write_intercepted(struct kvm_vcpu *vcpu, unsigned msr)
+{
+	u8 bit_write;
+	unsigned long tmp;
+	u32 offset;
+	u32 *msrpm;
+
+	msrpm = is_guest_mode(vcpu) ? to_svm(vcpu)->nested.msrpm:
+				      to_svm(vcpu)->msrpm;
+
+	offset    = svm_msrpm_offset(msr);
+	bit_write = 2 * (msr & 0x0f) + 1;
+	tmp       = msrpm[offset];
+
+	BUG_ON(offset == MSR_INVALID);
+
+	return !!test_bit(bit_write,  &tmp);
+}
+
 static void set_msr_interception(u32 *msrpm, unsigned msr,
 				 int read, int write)
 {
@@ -1206,6 +1228,8 @@ static void svm_vcpu_reset(struct kvm_vc
 	u32 dummy;
 	u32 eax = 1;
 
+	svm->spec_ctrl = 0;
+
 	init_vmcb(svm);
 
 	kvm_cpuid(vcpu, &eax, &dummy, &dummy, &dummy);
@@ -3112,6 +3136,13 @@ static int svm_get_msr(struct kvm_vcpu *
 	case MSR_VM_CR:
 		msr_info->data = svm->nested.vm_cr_msr;
 		break;
+	case MSR_IA32_SPEC_CTRL:
+		if (!msr_info->host_initiated &&
+		    !guest_cpuid_has_ibrs(vcpu))
+			return 1;
+
+		msr_info->data = svm->spec_ctrl;
+		break;
 	case MSR_IA32_UCODE_REV:
 		msr_info->data = 0x01000065;
 		break;
@@ -3184,6 +3215,33 @@ static int svm_set_msr(struct kvm_vcpu *
 	case MSR_IA32_TSC:
 		kvm_write_tsc(vcpu, msr);
 		break;
+	case MSR_IA32_SPEC_CTRL:
+		if (!msr->host_initiated &&
+		    !guest_cpuid_has_ibrs(vcpu))
+			return 1;
+
+		/* The STIBP bit doesn't fault even if it's not advertised */
+		if (data & ~(SPEC_CTRL_IBRS | SPEC_CTRL_STIBP))
+			return 1;
+
+		svm->spec_ctrl = data;
+
+		if (!data)
+			break;
+
+		/*
+		 * For non-nested:
+		 * When it's written (to non-zero) for the first time, pass
+		 * it through.
+		 *
+		 * For nested:
+		 * The handling of the MSR bitmap for L2 guests is done in
+		 * nested_svm_vmrun_msrpm.
+		 * We update the L1 MSR bit as well since it will end up
+		 * touching the MSR anyway now.
+		 */
+		set_msr_interception(svm->msrpm, MSR_IA32_SPEC_CTRL, 1, 1);
+		break;
 	case MSR_IA32_PRED_CMD:
 		if (!msr->host_initiated &&
 		    !guest_cpuid_has_ibpb(vcpu))
@@ -3902,6 +3960,15 @@ static void svm_vcpu_run(struct kvm_vcpu
 
 	local_irq_enable();
 
+	/*
+	 * If this vCPU has touched SPEC_CTRL, restore the guest's value if
+	 * it's non-zero. Since vmentry is serialising on affected CPUs, there
+	 * is no need to worry about the conditional branch over the wrmsr
+	 * being speculatively taken.
+	 */
+	if (svm->spec_ctrl)
+		wrmsrl(MSR_IA32_SPEC_CTRL, svm->spec_ctrl);
+
 	asm volatile (
 		"push %%" _ASM_BP "; \n\t"
 		"mov %c[rbx](%[svm]), %%" _ASM_BX " \n\t"
@@ -3994,6 +4061,27 @@ static void svm_vcpu_run(struct kvm_vcpu
 #endif
 		);
 
+	/*
+	 * We do not use IBRS in the kernel. If this vCPU has used the
+	 * SPEC_CTRL MSR it may have left it on; save the value and
+	 * turn it off. This is much more efficient than blindly adding
+	 * it to the atomic save/restore list. Especially as the former
+	 * (Saving guest MSRs on vmexit) doesn't even exist in KVM.
+	 *
+	 * For non-nested case:
+	 * If the L01 MSR bitmap does not intercept the MSR, then we need to
+	 * save it.
+	 *
+	 * For nested case:
+	 * If the L02 MSR bitmap does not intercept the MSR, then we need to
+	 * save it.
+	 */
+	if (!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL))
+		rdmsrl(MSR_IA32_SPEC_CTRL, svm->spec_ctrl);
+
+	if (svm->spec_ctrl)
+		wrmsrl(MSR_IA32_SPEC_CTRL, 0);
+
 	/* Eliminate branch target predictions from guest mode */
 	vmexit_fill_RSB();
 
#62 lore raw

PATCH 59/410 KVM/x86: Remove indirect MSR op calls from SPEC_CTRL

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Paolo Bonzini <[email protected]>

commit ecb586bd29c99fb4de599dec388658e74388daad upstream.

Having a paravirt indirect call in the IBRS restore path is not a good idea, since we are trying to protect from speculative execution of bogus indirect branch targets. It is also slower, so use native_wrmsrl() on the vmentry path too.

Cc David Woodhouse <[email protected]>
Cc KarimAllah Ahmed <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Radim Krčmář <[email protected]>
Cc Thomas Gleixner <[email protected]>
Fixes d28b387fb74da95d69d2615732f50cceb38e9a4d
[bwh: Backported to 3.16: adjust context]
---
 arch/x86/kvm/svm.c | 7 ++++---
 arch/x86/kvm/vmx.c | 7 ++++---
 2 files changed, 8 insertions(+), 6 deletions(-)
arch/x86/kvm/svm.c +4 -3
@@ -36,6 +36,7 @@
 #include <asm/desc.h>
 #include <asm/debugreg.h>
 #include <asm/kvm_para.h>
+#include <asm/microcode.h>
 #include <asm/nospec-branch.h>
 
 #include <asm/virtext.h>
@@ -3967,7 +3968,7 @@ static void svm_vcpu_run(struct kvm_vcpu
 	 * being speculatively taken.
 	 */
 	if (svm->spec_ctrl)
-		wrmsrl(MSR_IA32_SPEC_CTRL, svm->spec_ctrl);
+		native_wrmsrl(MSR_IA32_SPEC_CTRL, svm->spec_ctrl);
 
 	asm volatile (
 		"push %%" _ASM_BP "; \n\t"
@@ -4077,10 +4078,10 @@ static void svm_vcpu_run(struct kvm_vcpu
 	 * save it.
 	 */
 	if (!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL))
-		rdmsrl(MSR_IA32_SPEC_CTRL, svm->spec_ctrl);
+		svm->spec_ctrl = native_read_msr(MSR_IA32_SPEC_CTRL);
 
 	if (svm->spec_ctrl)
-		wrmsrl(MSR_IA32_SPEC_CTRL, 0);
+		native_wrmsrl(MSR_IA32_SPEC_CTRL, 0);
 
 	/* Eliminate branch target predictions from guest mode */
 	vmexit_fill_RSB();
arch/x86/kvm/vmx.c +4 -3
@@ -46,6 +46,7 @@
 #include <asm/perf_event.h>
 #include <asm/debugreg.h>
 #include <asm/kexec.h>
+#include <asm/microcode.h>
 #include <asm/nospec-branch.h>
 
 #include "trace.h"
@@ -7542,7 +7543,7 @@ static void __noclone vmx_vcpu_run(struc
 	 * being speculatively taken.
 	 */
 	if (vmx->spec_ctrl)
-		wrmsrl(MSR_IA32_SPEC_CTRL, vmx->spec_ctrl);
+		native_wrmsrl(MSR_IA32_SPEC_CTRL, vmx->spec_ctrl);
 
 	vmx->__launched = vmx->loaded_vmcs->launched;
 	asm(
@@ -7673,10 +7674,10 @@ static void __noclone vmx_vcpu_run(struc
 	 * save it.
 	 */
 	if (!msr_write_intercepted_l01(vcpu, MSR_IA32_SPEC_CTRL))
-		rdmsrl(MSR_IA32_SPEC_CTRL, vmx->spec_ctrl);
+		vmx->spec_ctrl = native_read_msr(MSR_IA32_SPEC_CTRL);
 
 	if (vmx->spec_ctrl)
-		wrmsrl(MSR_IA32_SPEC_CTRL, 0);
+		native_wrmsrl(MSR_IA32_SPEC_CTRL, 0);
 
 	/* Eliminate branch target predictions from guest mode */
 	vmexit_fill_RSB();
#63 lore raw

PATCH 60/410 x86/speculation: Move firmware_restrict_branch_speculation_*() from C to CPP

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Ingo Molnar <[email protected]>

commit d72f4e29e6d84b7ec02ae93088aa459ac70e733b upstream.

firmware_restrict_branch_speculation_*() recently started using preempt_enable()/disable(), but those are relatively high level primitives and cause build failures on some 32-bit builds.

Since we want to keep <asm/nospec-branch.h> low level, convert them to macros to avoid header hell...

---
 arch/x86/include/asm/nospec-branch.h | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)
arch/x86/include/asm/nospec-branch.h +14 -12
@@ -213,20 +213,22 @@ static inline void indirect_branch_predi
 /*
  * With retpoline, we must use IBRS to restrict branch prediction
  * before calling into firmware.
+ *
+ * (Implemented as CPP macros due to header hell.)
  */
-static inline void firmware_restrict_branch_speculation_start(void)
-{
-	preempt_disable();
-	alternative_msr_write(MSR_IA32_SPEC_CTRL, SPEC_CTRL_IBRS,
-			      X86_FEATURE_USE_IBRS_FW);
-}
+#define firmware_restrict_branch_speculation_start()			\
+do {									\
+	preempt_disable();						\
+	alternative_msr_write(MSR_IA32_SPEC_CTRL, SPEC_CTRL_IBRS,	\
+			      X86_FEATURE_USE_IBRS_FW);			\
+} while (0)
 
-static inline void firmware_restrict_branch_speculation_end(void)
-{
-	alternative_msr_write(MSR_IA32_SPEC_CTRL, 0,
-			      X86_FEATURE_USE_IBRS_FW);
-	preempt_enable();
-}
+#define firmware_restrict_branch_speculation_end()			\
+do {									\
+	alternative_msr_write(MSR_IA32_SPEC_CTRL, 0,			\
+			      X86_FEATURE_USE_IBRS_FW);			\
+	preempt_enable();						\
+} while (0)
 
 #endif /* __ASSEMBLY__ */
 #endif /* _ASM_X86_NOSPEC_BRANCH_H_ */
#64 lore raw

PATCH 61/410 KVM/VMX: Optimize vmx_vcpu_run() and svm_vcpu_run() by marking the RDMSR path as unlikely()

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Paolo Bonzini <[email protected]>

commit 946fbbc13dce68902f64515b610eeb2a6c3d7a64 upstream.

vmx_vcpu_run() and svm_vcpu_run() are large functions, and giving branch hints to the compiler can actually make a substantial cycle difference by keeping the fast path contiguous in memory.

With this optimization, the retpoline-guest/retpoline-host case is about 50 cycles faster.

Cc David Woodhouse <[email protected]>
Cc KarimAllah Ahmed <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Radim Krčmář <[email protected]>
Cc Thomas Gleixner <[email protected]>
[bwh: Backported to 3.16: adjust context]
---
 arch/x86/kvm/svm.c | 2 +-
 arch/x86/kvm/vmx.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/svm.c +1 -1
@@ -4077,7 +4077,7 @@ static void svm_vcpu_run(struct kvm_vcpu
 	 * If the L02 MSR bitmap does not intercept the MSR, then we need to
 	 * save it.
 	 */
-	if (!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL))
+	if (unlikely(!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL)))
 		svm->spec_ctrl = native_read_msr(MSR_IA32_SPEC_CTRL);
 
 	if (svm->spec_ctrl)
arch/x86/kvm/vmx.c +1 -1
@@ -7673,7 +7673,7 @@ static void __noclone vmx_vcpu_run(struc
 	 * If the L01 MSR bitmap does not intercept the MSR, then we need to
 	 * save it.
 	 */
-	if (!msr_write_intercepted_l01(vcpu, MSR_IA32_SPEC_CTRL))
+	if (unlikely(!msr_write_intercepted_l01(vcpu, MSR_IA32_SPEC_CTRL)))
 		vmx->spec_ctrl = native_read_msr(MSR_IA32_SPEC_CTRL);
 
 	if (vmx->spec_ctrl)
#65 lore raw

PATCH 62/410 x86/speculation: Use Indirect Branch Prediction Barrier in context switch

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Tim Chen <[email protected]>

commit 18bf3c3ea8ece8f03b6fc58508f2dfd23c7711c7 upstream.

Flush indirect branches when switching into a process that marked itself non dumpable. This protects high value processes like gpg better, without having too high performance overhead.

If done naïvely, we could switch to a kernel idle thread and then back to the original process, such as:

    process A -> idle -> process A

In such scenario, we do not have to do IBPB here even though the process is non-dumpable, as we are switching back to the same process after a hiatus.

To avoid the redundant IBPB, which is expensive, we track the last mm user context ID. The cost is to have an extra u64 mm context id to track the last mm we were using before switching to the init_mm used by idle. Avoiding the extra IBPB is probably worth the extra memory for this common scenario.

For those cases where tlb_defer_switch_to_init_mm() returns true (non PCID), lazy tlb will defer switch to init_mm, so we will not be changing the mm for the process A -> idle -> process A switch. So IBPB will be skipped for this case.

Thanks to the reviewers and Andy Lutomirski for the suggestion of using ctx_id which got rid of the problem of mm pointer recycling.

[bwh: Backported to 3.16: Drop the optimisation for switching via the idle
task, since we don't have mm_context_t::ctx_id here]

---

arch/x86/mm/tlb.c +19 -0
@@ -10,6 +10,7 @@
 
 #include <asm/tlbflush.h>
 #include <asm/mmu_context.h>
+#include <asm/nospec-branch.h>
 #include <asm/cache.h>
 #include <asm/apic.h>
 #include <asm/uv/uv.h>
@@ -100,6 +101,24 @@ void switch_mm_irqs_off(struct mm_struct
 	unsigned cpu = smp_processor_id();
 
 	if (likely(prev != next)) {
+		/*
+		 * Avoid user/user BTB poisoning by flushing the branch
+		 * predictor when switching between processes. This stops
+		 * one process from doing Spectre-v2 attacks on another.
+		 *
+		 * As an optimization, flush indirect branches only when
+		 * switching into processes that disable dumping. This
+		 * protects high value processes like gpg, without having
+		 * too high performance overhead. IBPB is *expensive*!
+		 *
+		 * This will not flush branches when switching into kernel
+		 * threads. It will flush if we switch to a different non-
+		 * dumpable process.
+		 */
+		if (tsk && tsk->mm &&
+		    get_dumpable(tsk->mm) != SUID_DUMP_USER)
+			indirect_branch_prediction_barrier();
+
 		this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
 		this_cpu_write(cpu_tlbstate.active_mm, next);
 		cpumask_set_cpu(cpu, mm_cpumask(next));
#66 lore raw

PATCH 63/410 x86/speculation: Update Speculation Control microcode blacklist

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: David Woodhouse <[email protected]>

commit 1751342095f0d2b36fa8114d8e12c5688c455ac4 upstream.

Intel have retroactively blessed the 0xc2 microcode on Skylake mobile and desktop parts, and the Gemini Lake 0x22 microcode is apparently fine too. We blacklisted the latter purely because it was present with all the other problematic ones in the 2018-01-08 release, but now it's explicitly listed as OK.

We still list 0x84 for the various Kaby Lake / Coffee Lake parts, as that appeared in one version of the blacklist and then reverted to 0x80 again. We can change it if 0x84 is actually announced to be safe.

---
 arch/x86/kernel/cpu/intel.c | 4 ----
 1 file changed, 4 deletions(-)
arch/x86/kernel/cpu/intel.c +0 -4
@@ -47,8 +47,6 @@ static const struct sku_microcode spectr
 	{ INTEL_FAM6_KABYLAKE_MOBILE,	0x09,	0x84 },
 	{ INTEL_FAM6_SKYLAKE_X,		0x03,	0x0100013e },
 	{ INTEL_FAM6_SKYLAKE_X,		0x04,	0x0200003c },
-	{ INTEL_FAM6_SKYLAKE_MOBILE,	0x03,	0xc2 },
-	{ INTEL_FAM6_SKYLAKE_DESKTOP,	0x03,	0xc2 },
 	{ INTEL_FAM6_BROADWELL_CORE,	0x04,	0x28 },
 	{ INTEL_FAM6_BROADWELL_GT3E,	0x01,	0x1b },
 	{ INTEL_FAM6_BROADWELL_XEON_D,	0x02,	0x14 },
@@ -60,8 +58,6 @@ static const struct sku_microcode spectr
 	{ INTEL_FAM6_HASWELL_X,		0x02,	0x3b },
 	{ INTEL_FAM6_HASWELL_X,		0x04,	0x10 },
 	{ INTEL_FAM6_IVYBRIDGE_X,	0x04,	0x42a },
-	/* Updated in the 20180108 release; blacklist until we know otherwise */
-	{ INTEL_FAM6_ATOM_GEMINI_LAKE,	0x01,	0x22 },
 	/* Observed in the wild */
 	{ INTEL_FAM6_SANDYBRIDGE_X,	0x06,	0x61b },
 	{ INTEL_FAM6_SANDYBRIDGE_X,	0x07,	0x712 },
#67 lore raw

PATCH 64/410 x86/speculation: Correct Speculation Control microcode blacklist again

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: David Woodhouse <[email protected]>

commit d37fc6d360a404b208547ba112e7dabb6533c7fc upstream.

Arjan points out that the Intel document only clears the 0xc2 microcode on *some* parts with CPUID 506E3 (INTEL_FAM6_SKYLAKE_DESKTOP stepping 3). For the Skylake H/S platform it's OK but for Skylake E3 which has the same CPUID it isn't (yet) cleared.

So removing it from the blacklist was premature. Put it back for now.

Also, Arjan assures me that the 0x84 microcode for Kaby Lake which was featured in one of the early revisions of the Intel document was never released to the public, and won't be until/unless it is also validated as safe. So those can change to 0x80 which is what all *other* versions of the doc have identified.

Once the retrospective testing of existing public microcodes is done, we should be back into a mode where new microcodes are only released in batches and we shouldn't even need to update the blacklist for those anyway, so this tweaking of the list isn't expected to be a thing which keeps happening.

---
 arch/x86/kernel/cpu/intel.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/intel.c +6 -5
@@ -40,13 +40,14 @@ struct sku_microcode {
 	u32 microcode;
 };
 static const struct sku_microcode spectre_bad_microcodes[] = {
-	{ INTEL_FAM6_KABYLAKE_DESKTOP,	0x0B,	0x84 },
-	{ INTEL_FAM6_KABYLAKE_DESKTOP,	0x0A,	0x84 },
-	{ INTEL_FAM6_KABYLAKE_DESKTOP,	0x09,	0x84 },
-	{ INTEL_FAM6_KABYLAKE_MOBILE,	0x0A,	0x84 },
-	{ INTEL_FAM6_KABYLAKE_MOBILE,	0x09,	0x84 },
+	{ INTEL_FAM6_KABYLAKE_DESKTOP,	0x0B,	0x80 },
+	{ INTEL_FAM6_KABYLAKE_DESKTOP,	0x0A,	0x80 },
+	{ INTEL_FAM6_KABYLAKE_DESKTOP,	0x09,	0x80 },
+	{ INTEL_FAM6_KABYLAKE_MOBILE,	0x0A,	0x80 },
+	{ INTEL_FAM6_KABYLAKE_MOBILE,	0x09,	0x80 },
 	{ INTEL_FAM6_SKYLAKE_X,		0x03,	0x0100013e },
 	{ INTEL_FAM6_SKYLAKE_X,		0x04,	0x0200003c },
+	{ INTEL_FAM6_SKYLAKE_DESKTOP,	0x03,	0xc2 },
 	{ INTEL_FAM6_BROADWELL_CORE,	0x04,	0x28 },
 	{ INTEL_FAM6_BROADWELL_GT3E,	0x01,	0x1b },
 	{ INTEL_FAM6_BROADWELL_XEON_D,	0x02,	0x14 },
#68 lore raw

PATCH 65/410 perf evlist: Introduce perf_evlist__new_dummy constructor

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Arnaldo Carvalho de Melo <[email protected]>

commit 5bae0250237f7a5ec4355f9920701de247b8db91 upstream.

For case where all we need is an evlist with just an "dummy" evsel, like in some 'perf test' entries.

---
 tools/perf/util/evlist.c | 28 ++++++++++++++++++++++++++++
 tools/perf/util/evlist.h |  3 +++
 2 files changed, 31 insertions(+)
tools/perf/util/evlist.c +28 -0
@@ -62,6 +62,18 @@ struct perf_evlist *perf_evlist__new_def
 	return evlist;
 }
 
+struct perf_evlist *perf_evlist__new_dummy(void)
+{
+	struct perf_evlist *evlist = perf_evlist__new();
+
+	if (evlist && perf_evlist__add_dummy(evlist)) {
+		perf_evlist__delete(evlist);
+		evlist = NULL;
+	}
+
+	return evlist;
+}
+
 /**
  * perf_evlist__set_id_pos - set the positions of event ids.
  * @evlist: selected event list
@@ -188,6 +200,22 @@ error:
 	return -ENOMEM;
 }
 
+int perf_evlist__add_dummy(struct perf_evlist *evlist)
+{
+	struct perf_event_attr attr = {
+		.type	= PERF_TYPE_SOFTWARE,
+		.config = PERF_COUNT_SW_DUMMY,
+		.size	= sizeof(attr), /* to capture ABI version */
+	};
+	struct perf_evsel *evsel = perf_evsel__new(&attr);
+
+	if (evsel == NULL)
+		return -ENOMEM;
+
+	perf_evlist__add(evlist, evsel);
+	return 0;
+}
+
 static int perf_evlist__add_attrs(struct perf_evlist *evlist,
 				  struct perf_event_attr *attrs, size_t nr_attrs)
 {
tools/perf/util/evlist.h +3 -0
@@ -54,6 +54,7 @@ struct perf_evsel_str_handler {
 
 struct perf_evlist *perf_evlist__new(void);
 struct perf_evlist *perf_evlist__new_default(void);
+struct perf_evlist *perf_evlist__new_dummy(void);
 void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus,
 		       struct thread_map *threads);
 void perf_evlist__exit(struct perf_evlist *evlist);
@@ -67,6 +68,8 @@ int __perf_evlist__add_default_attrs(str
 #define perf_evlist__add_default_attrs(evlist, array) \
 	__perf_evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array))
 
+int perf_evlist__add_dummy(struct perf_evlist *evlist);
+
 int perf_evlist__add_newtp(struct perf_evlist *evlist,
 			   const char *sys, const char *name, void *handler);
 
#69 lore raw

PATCH 66/410 perf record: Generate PERF_RECORD_{MMAP,COMM,EXEC} with --delay

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Arnaldo Carvalho de Melo <[email protected]>

commit d3dbf43c56f9176be325ce1cc72a44c8d3c210dc upstream.

When we use an initial delay, e.g.: 'perf record --delay 1000', we do not enable the events until that delay has passed after we started the workload, including the tracking event, i.e. the one for which we have attr.mmap, etc, enabled to ask the kernel to generate the PERF_RECORD_{MMAP,COMM,EXEC} metadata events that will then allow us to resolve addresses in samples to the map, dso and symbol. There will be a shadow that even synthesizing samples won't cover, i.e. the workload that we start and other processes forking while we wait for the initial delay to expire.

So use a dummy event to be the tracking one and make it be enabled on exec.

Before:

  # perf record --delay 1000 stress --cpu 1 --timeout 5
  stress: info: [9029] dispatching hogs: 1 cpu, 0 io, 0 vm, 0 hdd
  stress: info: [9029] successful run completed in 5s
  [ perf record: Woken up 3 times to write data ]
  [ perf record: Captured and wrote 0.624 MB perf.data (15908 samples) ]
  # perf script | head
      :9031 9031 32001.826888:       1 cycles:ppp: ffffffff831aa30d event_function (/lib/modules/4.14.0-rc6+/build/vmlinux)
      :9031 9031 32001.826893:       1 cycles:ppp: ffffffff8300d1a0 intel_bts_enable_local (/lib/modules/4.14.0-rc6+/build/vmlinux)
      :9031 9031 32001.826895:       7 cycles:ppp: ffffffff83023870 sched_clock (/lib/modules/4.14.0-rc6+/build/vmlinux)
      :9031 9031 32001.826897:     103 cycles:ppp: ffffffff8300c331 intel_pmu_handle_irq (/lib/modules/4.14.0-rc6+/build/vmlinux)
      :9031 9031 32001.826899:    1615 cycles:ppp: ffffffff830231f8 native_sched_clock (/lib/modules/4.14.0-rc6+/build/vmlinux)
      :9031 9031 32001.826902:   26724 cycles:ppp: ffffffff8384c6a7 native_irq_return_iret (/lib/modules/4.14.0-rc6+/build/vmlinux)
      :9031 9031 32001.826913:  329739 cycles:ppp:     7fb2a5410932 [unknown] ([unknown])
      :9031 9031 32001.827033: 1225451 cycles:ppp:     7fb2a5410930 [unknown] ([unknown])
      :9031 9031 32001.827474: 1391725 cycles:ppp:     7fb2a5410930 [unknown] ([unknown])
      :9031 9031 32001.827978: 1233697 cycles:ppp:     7fb2a5410928 [unknown] ([unknown])
  #

After:

  # perf record --delay 1000 stress --cpu 1 --timeout 5
  stress: info: [9741] dispatching hogs: 1 cpu, 0 io, 0 vm, 0 hdd
  stress: info: [9741] successful run completed in 5s
  [ perf record: Woken up 3 times to write data ]
  [ perf record: Captured and wrote 0.751 MB perf.data (15976 samples) ]
  # perf script | head
     stress  9742 32110.959106:          1 cycles:ppp:  ffffffff831b26f6 __perf_event_task_sched_in (/lib/modules/4.14.0-rc6+/build/vmlinux)
     stress 9742 32110.959110:       1 cycles:ppp: ffffffff8300c2e9 intel_pmu_handle_irq (/lib/modules/4.14.0-rc6+/build/vmlinux)
     stress 9742 32110.959112:       7 cycles:ppp: ffffffff830231e0 native_sched_clock (/lib/modules/4.14.0-rc6+/build/vmlinux)
     stress 9742 32110.959115:     101 cycles:ppp: ffffffff83023870 sched_clock (/lib/modules/4.14.0-rc6+/build/vmlinux)
     stress 9742 32110.959117:    1533 cycles:ppp: ffffffff830231f8 native_sched_clock (/lib/modules/4.14.0-rc6+/build/vmlinux)
     stress 9742 32110.959119:   23992 cycles:ppp: ffffffff831b0900 ctx_sched_in (/lib/modules/4.14.0-rc6+/build/vmlinux)
     stress 9742 32110.959129:  329406 cycles:ppp:     7f4b1b661930 __random_r (/usr/lib64/libc-2.25.so)
     stress 9742 32110.959249: 1288322 cycles:ppp:     5566e1e7cbc9 hogcpu (/usr/bin/stress)
     stress 9742 32110.959712: 1464046 cycles:ppp:     7f4b1b66179e __random (/usr/lib64/libc-2.25.so)
     stress 9742 32110.960241: 1266918 cycles:ppp:     7f4b1b66195b __random_r (/usr/lib64/libc-2.25.so)
  #
Cc Adrian Hunter <[email protected]>
Cc Andi Kleen <[email protected]>
Cc David Ahern <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Wang Nan <[email protected]>
Fixes 6619a53ef757 ("perf record: Add --initial-delay option")

[bwh: Backported to 3.16:
- Don't set perf_evsel::tracking fields
- Adjust context]

---

tools/perf/builtin-record.c +13 -0
@@ -140,6 +140,19 @@ static int record__open(struct record *r
 	struct record_opts *opts = &rec->opts;
 	int rc = 0;
 
+	/*
+	 * For initial_delay we need to add a dummy event so that we can track
+	 * PERF_RECORD_MMAP while we wait for the initial delay to enable the
+	 * real events, the ones asked by the user.
+	 */
+	if (opts->initial_delay) {
+		if (perf_evlist__add_dummy(evlist))
+			return -ENOMEM;
+
+		pos = perf_evlist__last(evlist);
+		pos->attr.enable_on_exec = 1;
+	}
+
 	perf_evlist__config(evlist, opts);
 
 	evlist__for_each(evlist, pos) {
#70 lore raw

PATCH 67/410 EDAC, octeon: Fix an uninitialized variable warning

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: James Hogan <[email protected]>

commit 544e92581a2ac44607d7cc602c6b54d18656f56d upstream.

Fix an uninitialized variable warning in the Octeon EDAC driver, as seen in MIPS cavium_octeon_defconfig builds since v4.14 with Codescape GNU Tools 2016.05-03:

drivers/edac/octeon_edac-lmc.c In function ‘octeon_lmc_edac_poll_o2’:

  drivers/edac/octeon_edac-lmc.c:87:24: warning: ‘((long unsigned int*)&int_reg)[1]’ may \
    be used uninitialized in this function [-Wmaybe-uninitialized]
    if (int_reg.s.sec_err || int_reg.s.ded_err) {
                        ^

Iinitialise the whole int_reg variable to zero before the conditional assignments in the error injection case.

---
 drivers/edac/octeon_edac-lmc.c | 1 +
 1 file changed, 1 insertion(+)

--
To unsubscribe from this list: send the line "unsubscribe linux-edac" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

drivers/edac/octeon_edac-lmc.c +1 -0
@@ -79,6 +79,7 @@ static void octeon_lmc_edac_poll_o2(stru
 	if (!pvt->inject)
 		int_reg.u64 = cvmx_read_csr(CVMX_LMCX_INT(mci->mc_idx));
 	else {
+		int_reg.u64 = 0;
 		if (pvt->error_type == 1)
 			int_reg.s.sec_err = 1;
 		if (pvt->error_type == 2)
#71 lore raw

PATCH 68/410 ARM: dts: exynos: Correct Trats2 panel reset line

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Simon Shields <[email protected]>

commit 1b377924841df1e13ab5b225be3a83f807a92b52 upstream.

Trats2 uses gpf2-1 as the panel reset GPIO. gpy4-5 was only used on early revisions of the board.

Fixes 420ae8451a22 ("ARM: dts: exynos4412-trats2: add panel node")
[bwh: Backported to 3.16: adjust context]
---
 arch/arm/boot/dts/exynos4412-trats2.dts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/boot/dts/exynos4412-trats2.dts +1 -1
@@ -628,7 +628,7 @@
 			reg = <0>;
 			vdd3-supply = <&lcd_vdd3_reg>;
 			vci-supply = <&ldo25_reg>;
-			reset-gpios = <&gpy4 5 0>;
+			reset-gpios = <&gpf2 1 0>;
 			power-on-delay= <50>;
 			reset-delay = <100>;
 			init-delay = <100>;
#72 lore raw

PATCH 69/410 perf report: Fix -D output for user metadata events

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Arnaldo Carvalho de Melo <[email protected]>

commit f250b09c779550e4a7a412dae6d3ad34d5201019 upstream.

The PERF_RECORD_USER_ events are synthesized by the tool to assist in processing the PERF_RECORD_ ones generated by the kernel, the printing of that information doesn't come with a perf_sample structure, so, when dumping the event fields using 'perf report -D' there were columns that end up not being printed.

To tidy up a bit this, fake a perf_sample structure with zeroes to have the missing columns printed and avoid the occasional surprise with that.

Before:

0 0x45b8 [0x68]: PERF_RECORD_MMAP -1/0: [0xffffffffc12ec000(0x4000) @ 0]: x /lib/modules/4.14.0+/kernel/fs/nls/nls_utf8.ko 0x4620 [0x28]: PERF_RECORD_THREAD_MAP nr: 1 thread: 27820
0x4648 [0x18]: PERF_RECORD_CPU_MAP: 0-3
0 0x4660 [0x28]: PERF_RECORD_COMM: perf:27820/27820
0x4a58 [0x8]: PERF_RECORD_FINISHED_ROUND
447723433020976 0x4688 [0x28]: PERF_RECORD_SAMPLE(IP, 0x4001): 27820/27820: 0xffffffff8f1b6d7a period: 1 addr: 0

After:

  $ perf report -D | grep PERF_RECORD_ | head
  0 0xe8 [0x20]: PERF_RECORD_TIME_CONV: unhandled!
  0 0x108 [0x28]: PERF_RECORD_THREAD_MAP nr: 1 thread: 32555
  0 0x130 [0x18]: PERF_RECORD_CPU_MAP: 0-3
  0 0x148 [0x28]: PERF_RECORD_COMM: perf:32555/32555
  0 0x4e8 [0x8]: PERF_RECORD_FINISHED_ROUND
  448743409421205 0x170 [0x28]: PERF_RECORD_COMM exec: sleep:32555/32555
  448743409431883 0x198 [0x68]: PERF_RECORD_MMAP2 32555/32555: [0x55e11d75a000(0x208000) @ 0 fd:00 3147174 2566255743]: r-xp /usr/bin/sleep
  448743409443873 0x200 [0x70]: PERF_RECORD_MMAP2 32555/32555: [0x7f0ced316000(0x229000) @ 0 fd:00 3151761 2566238119]: r-xp /usr/lib64/ld-2.25.so
  448743409454790 0x270 [0x60]: PERF_RECORD_MMAP2 32555/32555: [0x7ffe84f6d000(0x2000) @ 0 00:00 0 0]: r-xp [vdso]
  448743409479500 0x2d0 [0x28]: PERF_RECORD_SAMPLE(IP, 0x4002): 32555/32555: 0xffffffff8f84c7e7 period: 1 addr: 0
  $
Cc Adrian Hunter <[email protected]>
Cc Andi Kleen <[email protected]>
Cc David Ahern <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Wang Nan <[email protected]>
Cc Thomas Gleixner <[email protected]>
Fixes 9aefcab0de47 ("perf session: Consolidate the dump code")
[bwh: Backported to 3.16: adjust context]
---
 tools/perf/util/session.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/session.c +2 -1
@@ -996,10 +996,11 @@ static int perf_session_deliver_event(st
 static int perf_session__process_user_event(struct perf_session *session, union perf_event *event,
 					    struct perf_tool *tool, u64 file_offset)
 {
+	struct perf_sample sample = { .time = 0, };
 	int fd = perf_data_file__fd(session->file);
 	int err;
 
-	dump_event(session, event, file_offset, NULL);
+	dump_event(session, event, file_offset, &sample);
 
 	/* These events are processed right away */
 	switch (event->header.type) {
#73 lore raw

PATCH 70/410 ARM: dts: omap3-n900: Fix the audio CODEC's reset pin

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: "Andrew F. Davis" <[email protected]>

commit 7be4b5dc7ffa9499ac6ef33a5ffa9ff43f9b7057 upstream.

The correct DT property for specifying a GPIO used for reset is "reset-gpios", fix this here.

Fixes 14e3e295b2b9 ("ARM: dts: omap3-n900: Add TLV320AIC3X support")
---
 arch/arm/boot/dts/omap3-n900.dts | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/boot/dts/omap3-n900.dts +2 -2
@@ -427,7 +427,7 @@
 	tlv320aic3x: tlv320aic3x@18 {
 		compatible = "ti,tlv320aic3x";
 		reg = <0x18>;
-		gpio-reset = <&gpio2 28 GPIO_ACTIVE_HIGH>; /* 60 */
+		reset-gpios = <&gpio2 28 GPIO_ACTIVE_LOW>; /* 60 */
 		ai3x-gpio-func = <
 			0 /* AIC3X_GPIO1_FUNC_DISABLED */
 			5 /* AIC3X_GPIO2_FUNC_DIGITAL_MIC_INPUT */
@@ -444,7 +444,7 @@
 	tlv320aic3x_aux: tlv320aic3x@19 {
 		compatible = "ti,tlv320aic3x";
 		reg = <0x19>;
-		gpio-reset = <&gpio2 28 GPIO_ACTIVE_HIGH>; /* 60 */
+		reset-gpios = <&gpio2 28 GPIO_ACTIVE_LOW>; /* 60 */
 
 		AVDD-supply = <&vmmc2>;
 		DRVDD-supply = <&vmmc2>;
#74 lore raw

Re: [PATCH 3.16 070/410] ARM: dts: omap3-n900: Fix the audio CODEC's reset pin

Quoted 2 lines · Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

This relies on a patch that may not have been back-ported this far back, it is more safe to not take this patch.

Quoted 39 lines

------------------

From: "Andrew F. Davis" <[email protected]>

commit 7be4b5dc7ffa9499ac6ef33a5ffa9ff43f9b7057 upstream.

The correct DT property for specifying a GPIO used for reset is "reset-gpios", fix this here.

Fixes 14e3e295b2b9 ("ARM: dts: omap3-n900: Add TLV320AIC3X support")
---
 arch/arm/boot/dts/omap3-n900.dts | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/boot/dts/omap3-n900.dts +2 -2
@@ -427,7 +427,7 @@
 	tlv320aic3x: tlv320aic3x@18 {
 		compatible = "ti,tlv320aic3x";
 		reg = <0x18>;
-		gpio-reset = <&gpio2 28 GPIO_ACTIVE_HIGH>; /* 60 */
+		reset-gpios = <&gpio2 28 GPIO_ACTIVE_LOW>; /* 60 */
 		ai3x-gpio-func = <
 			0 /* AIC3X_GPIO1_FUNC_DISABLED */
 			5 /* AIC3X_GPIO2_FUNC_DIGITAL_MIC_INPUT */
@@ -444,7 +444,7 @@
 	tlv320aic3x_aux: tlv320aic3x@19 {
 		compatible = "ti,tlv320aic3x";
 		reg = <0x19>;
-		gpio-reset = <&gpio2 28 GPIO_ACTIVE_HIGH>; /* 60 */
+		reset-gpios = <&gpio2 28 GPIO_ACTIVE_LOW>; /* 60 */
 
 		AVDD-supply = <&vmmc2>;
 		DRVDD-supply = <&vmmc2>;
#75 lore raw

Re: [PATCH 3.16 070/410] ARM: dts: omap3-n900: Fix the audio CODEC's reset pin

Quoted 7 lines · Andrew F. Davis
Quoted 2 lines · Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

This relies on a patch that may not have been back-ported this far back, it is more safe to not take this patch.

I agree, and I should have spotted that since I pointed it out in an earlier review.

Ben.

Quoted 40 lines
Quoted 40 lines

------------------

From: "Andrew F. Davis" <[email protected]>

commit 7be4b5dc7ffa9499ac6ef33a5ffa9ff43f9b7057 upstream.

The correct DT property for specifying a GPIO used for reset is "reset-gpios", fix this here.

Fixes 14e3e295b2b9 ("ARM: dts: omap3-n900: Add TLV320AIC3X support")
---
 arch/arm/boot/dts/omap3-n900.dts | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/boot/dts/omap3-n900.dts +2 -2
@@ -427,7 +427,7 @@
 	tlv320aic3x: tlv320aic3x@18 {
 		compatible = "ti,tlv320aic3x";
 		reg = <0x18>;
-		gpio-reset = <&gpio2 28 GPIO_ACTIVE_HIGH>; /* 60 */
+		reset-gpios = <&gpio2 28 GPIO_ACTIVE_LOW>; /* 60 */
 		ai3x-gpio-func = <
 			0 /* AIC3X_GPIO1_FUNC_DISABLED */
 			5 /* AIC3X_GPIO2_FUNC_DIGITAL_MIC_INPUT */
@@ -444,7 +444,7 @@
 	tlv320aic3x_aux: tlv320aic3x@19 {
 		compatible = "ti,tlv320aic3x";
 		reg = <0x19>;
-		gpio-reset = <&gpio2 28 GPIO_ACTIVE_HIGH>; /* 60 */
+		reset-gpios = <&gpio2 28 GPIO_ACTIVE_LOW>; /* 60 */
 
 		AVDD-supply = <&vmmc2>;
 		DRVDD-supply = <&vmmc2>;
Signature · 3 lines
Ben Hutchings
The most exhausting thing in life is being insincere.
                                                 - Anne Morrow Lindberg
#76 lore raw

PATCH 71/410 power: supply: ab8500_charger: Fix an error handling path

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Christophe JAILLET <[email protected]>

commit bf59fddde1c3eab89eb8dca8f3d3dc097887d2bb upstream.

'ret' is know to be 0 at this point, because it has not been updated by the the previous call to 'abx500_mask_and_set_register_interruptible()'.

Fix it by updating 'ret' before checking if an error occurred.

Fixes 84edbeeab67c ("ab8500-charger: AB8500 charger driver")
[bwh: Backported to 3.16: adjust filename]
---
 drivers/power/ab8500_charger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/ab8500_charger.c +1 -1
@@ -3224,7 +3224,7 @@ static int ab8500_charger_init_hw_regist
 	}
 
 	/* Enable backup battery charging */
-	abx500_mask_and_set_register_interruptible(di->dev,
+	ret = abx500_mask_and_set_register_interruptible(di->dev,
 		AB8500_RTC, AB8500_RTC_CTRL_REG,
 		RTC_BUP_CH_ENA, RTC_BUP_CH_ENA);
 	if (ret < 0)
#77 lore raw

PATCH 72/410 power: supply: ab8500_charger: Bail out in case of error in 'ab8500_charger_init_hw_registers()'

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Christophe JAILLET <[email protected]>

commit 09edcb647542487864e23aa8d2ef26be3e08978a upstream.

If an error occurs when we enable the backup battery charging, we should go through the error handling path directly.

Before commit db43e6c473b5 ("ab8500-bm: Add usb power path support") this was the case, but this commit has added some code between the last test and the 'out' label.
So, in case of error, this added code is executed and the error may be silently ignored.

Fix it by adding the missing 'goto out', as done in all other error handling paths.

Fixes db43e6c473b5 ("ab8500-bm: Add usb power path support")
[bwh: Backported to 3.16: adjust filename]
---
 drivers/power/ab8500_charger.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/power/ab8500_charger.c +3 -1
@@ -3227,8 +3227,10 @@ static int ab8500_charger_init_hw_regist
 	ret = abx500_mask_and_set_register_interruptible(di->dev,
 		AB8500_RTC, AB8500_RTC_CTRL_REG,
 		RTC_BUP_CH_ENA, RTC_BUP_CH_ENA);
-	if (ret < 0)
+	if (ret < 0) {
 		dev_err(di->dev, "%s mask and set failed\n", __func__);
+		goto out;
+	}
 
 	if (is_ab8540(di->parent)) {
 		ret = abx500_mask_and_set_register_interruptible(di->dev,
#78 lore raw

PATCH 73/410 perf annotate: Fix objdump comment parsing for Intel mov dissassembly

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Thomas Richter <[email protected]>

commit 35a8a148d8c1ee9e5ae18f9565a880490f816f89 upstream.

The command 'perf annotate' parses the output of objdump and also investigates the comments produced by objdump. For example the output of objdump produces (on x86):

23eee: 4c 8b 3d 13 01 21 00 mov 0x210113(%rip),%r15

                                # 234008 <stderr@@GLIBC_2.2.5+0x9a8>

and the function mov__parse() is called to investigate the complete line. Mov__parse() breaks this line into several parts and finally calls function comment__symbol() to parse the data after the comment character '#'. Comment__symbol() expects a hexadecimal address followed by a symbol in '<' and '>' brackets.

However the 2nd parameter given to function comment__symbol() always points to the comment character '#'. The address parsing always returns 0 because the character '#' is not a digit and strtoull() fails without being noticed.

Fix this by advancing the second parameter to function comment__symbol() by one byte before invocation and add an error check after strtoull() has been called.

Cc Heiko Carstens <[email protected]>
Cc Martin Schwidefsky <[email protected]>
Fixes 6de783b6f50f ("perf annotate: Resolve symbols using objdump comment")
[bwh: Backported to 3.16: adjust context]
---
 tools/perf/util/annotate.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
tools/perf/util/annotate.c +5 -3
@@ -146,6 +146,8 @@ static int comment__symbol(char *raw, ch
 		return 0;
 
 	*addrp = strtoull(comment, &endptr, 16);
+	if (endptr == comment)
+		return 0;
 	name = strchr(endptr, '<');
 	if (name == NULL)
 		return -1;
@@ -251,8 +253,8 @@ static int mov__parse(struct ins_operand
 	while (comment[0] != '\0' && isspace(comment[0]))
 		++comment;
 
-	comment__symbol(ops->source.raw, comment, &ops->source.addr, &ops->source.name);
-	comment__symbol(ops->target.raw, comment, &ops->target.addr, &ops->target.name);
+	comment__symbol(ops->source.raw, comment + 1, &ops->source.addr, &ops->source.name);
+	comment__symbol(ops->target.raw, comment + 1, &ops->target.addr, &ops->target.name);
 
 	return 0;
 
@@ -298,7 +300,7 @@ static int dec__parse(struct ins_operand
 	while (comment[0] != '\0' && isspace(comment[0]))
 		++comment;
 
-	comment__symbol(ops->target.raw, comment, &ops->target.addr, &ops->target.name);
+	comment__symbol(ops->target.raw, comment + 1, &ops->target.addr, &ops->target.name);
 
 	return 0;
 }
#79 lore raw

PATCH 74/410 HID: add quirk for another PIXART OEM mouse used by HP

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Dave Young <[email protected]>

commit 01cffe9ded15c0d664e0beb33c594e00c0d57bba upstream.

This mouse keep disconnecting in runleve 3 like below, add it needs the quirk to mute the anoying messages.

[  111.230555] usb 2-2: USB disconnect, device number 6
[  112.718156] usb 2-2: new low-speed USB device number 7 using xhci_hcd
[  112.941594] usb 2-2: New USB device found, idVendor=03f0, idProduct=094a
[  112.984866] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[  113.027731] usb 2-2: Product: HP USB Optical Mouse
[  113.069977] usb 2-2: Manufacturer: PixArt
[  113.113500] input: PixArt HP USB Optical Mouse as /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/0003:03F0:094A.0002/input/input14
[  113.156787] hid-generic 0003:03F0:094A.0002: input: USB HID v1.11 Mouse [PixArt HP USB Optical Mouse] on usb-0000:00:14.0-2/input0
[  173.262642] usb 2-2: USB disconnect, device number 7
[  174.750244] usb 2-2: new low-speed USB device number 8 using xhci_hcd
[  174.935740] usb 2-2: New USB device found, idVendor=03f0, idProduct=094a
[  174.990435] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[  175.014984] usb 2-2: Product: HP USB Optical Mouse
[  175.037886] usb 2-2: Manufacturer: PixArt
[  175.061794] input: PixArt HP USB Optical Mouse as /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/0003:03F0:094A.0003/input/input15
[  175.084946] hid-generic 0003:03F0:094A.0003: input: USB HID v1.11 Mouse [PixArt HP USB Optical Mouse] on usb-0000:00:14.0-2/input0

[bwh: Backported to 3.16:
- Don't use HID_USB_DEVICE()
- Adjust filename, context]

---
 drivers/hid/hid-ids.h           | 1 +
 drivers/hid/usbhid/hid-quirks.c | 1 +
 2 files changed, 2 insertions(+)
drivers/hid/hid-ids.h +1 -0
@@ -488,6 +488,7 @@
 #define USB_PRODUCT_ID_HP_LOGITECH_OEM_USB_OPTICAL_MOUSE_0A4A	0x0a4a
 #define USB_PRODUCT_ID_HP_LOGITECH_OEM_USB_OPTICAL_MOUSE_0B4A	0x0b4a
 #define USB_PRODUCT_ID_HP_PIXART_OEM_USB_OPTICAL_MOUSE		0x134a
+#define USB_PRODUCT_ID_HP_PIXART_OEM_USB_OPTICAL_MOUSE_094A	0x094a
 
 #define USB_VENDOR_ID_HUION		0x256c
 #define USB_DEVICE_ID_HUION_580		0x006e
drivers/hid/usbhid/hid-quirks.c +1 -0
@@ -99,6 +99,7 @@ static const struct hid_blacklist {
 	{ USB_VENDOR_ID_HP, USB_PRODUCT_ID_HP_LOGITECH_OEM_USB_OPTICAL_MOUSE_0A4A, HID_QUIRK_ALWAYS_POLL },
 	{ USB_VENDOR_ID_HP, USB_PRODUCT_ID_HP_LOGITECH_OEM_USB_OPTICAL_MOUSE_0B4A, HID_QUIRK_ALWAYS_POLL },
 	{ USB_VENDOR_ID_HP, USB_PRODUCT_ID_HP_PIXART_OEM_USB_OPTICAL_MOUSE, HID_QUIRK_ALWAYS_POLL },
+	{ USB_VENDOR_ID_HP, USB_PRODUCT_ID_HP_PIXART_OEM_USB_OPTICAL_MOUSE_094A, HID_QUIRK_ALWAYS_POLL },
 	{ USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_C077, HID_QUIRK_ALWAYS_POLL },
 	{ USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_KEYBOARD_G710_PLUS, HID_QUIRK_NOGET },
 	{ USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOUSE_C01A, HID_QUIRK_ALWAYS_POLL },
#80 lore raw

PATCH 75/410 spi: sun6i: disable/unprepare clocks on remove

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Tobias Jordan <[email protected]>

commit 2d9bbd02c54094ceffa555143b0d68cd06504d63 upstream.

sun6i_spi_probe() uses sun6i_spi_runtime_resume() to prepare/enable clocks, so sun6i_spi_remove() should use sun6i_spi_runtime_suspend() to disable/unprepare them if we're not suspended.
Replacing pm_runtime_disable() by pm_runtime_force_suspend() will ensure that sun6i_spi_runtime_suspend() is called if needed.

Found by Linux Driver Verification project (linuxtesting.org).

Fixes 3558fe900e8af (spi: sunxi: Add Allwinner A31 SPI controller driver)
---
 drivers/spi/spi-sun6i.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi-sun6i.c +1 -1
@@ -457,7 +457,7 @@ err_free_master:
 
 static int sun6i_spi_remove(struct platform_device *pdev)
 {
-	pm_runtime_disable(&pdev->dev);
+	pm_runtime_force_suspend(&pdev->dev);
 
 	return 0;
 }
#81 lore raw

PATCH 76/410 media: cpia2: Fix a couple off by one bugs

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Dan Carpenter <[email protected]>

commit d5ac225c7d64c9c3ef821239edc035634e594ec9 upstream.

The cam->buffers[] array has cam->num_frames elements so the > needs to be changed to >= to avoid going beyond the end of the array. The ->buffers[] array is allocated in cpia2_allocate_buffers() if you want to confirm.

Fixes ab33d5071de7 ("V4L/DVB (3376): Add cpia2 camera support")
---
 drivers/media/usb/cpia2/cpia2_v4l.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/usb/cpia2/cpia2_v4l.c +2 -2
@@ -812,7 +812,7 @@ static int cpia2_querybuf(struct file *f
 	struct camera_data *cam = video_drvdata(file);
 
 	if(buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
-	   buf->index > cam->num_frames)
+	   buf->index >= cam->num_frames)
 		return -EINVAL;
 
 	buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer;
@@ -863,7 +863,7 @@ static int cpia2_qbuf(struct file *file,
 
 	if(buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
 	   buf->memory != V4L2_MEMORY_MMAP ||
-	   buf->index > cam->num_frames)
+	   buf->index >= cam->num_frames)
 		return -EINVAL;
 
 	DBG("QBUF #%d\n", buf->index);
#82 lore raw

PATCH 77/410 slip: sl_alloc(): remove unused parameter "dev_t line"

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Marc Kleine-Budde <[email protected]>

commit 936e5d8bdfa72577e28ea671d9e2ee4fef0d6b3e upstream.

The first and only parameter of sl_alloc() is unused, so remove it.

Fixes 5342b77c4123 slip: ("Clean up create and destroy")
---
 drivers/net/slip/slip.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/slip/slip.c +2 -2
@@ -732,7 +732,7 @@ static void sl_sync(void)
 
 
 /* Find a free SLIP channel, and link in this `tty' line. */
-static struct slip *sl_alloc(dev_t line)
+static struct slip *sl_alloc(void)
 {
 	int i;
 	char name[IFNAMSIZ];
@@ -814,7 +814,7 @@ static int slip_open(struct tty_struct *
 
 	/* OK.  Find a free SLIP channel to use. */
 	err = -ENFILE;
-	sl = sl_alloc(tty_devnum(tty));
+	sl = sl_alloc();
 	if (sl == NULL)
 		goto err_exit;
 
#83 lore raw

PATCH 78/410 powerpc/64: Don't trace irqs-off at interrupt return to soft-disabled context

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Nicholas Piggin <[email protected]>

commit acb1feab320e38588fccc568e3767761f494976f upstream.

When an interrupt is returning to a soft-disabled context (which can happen for non-maskable interrupts or synchronous interrupts), it goes through the motions of soft-disabling again, including calling TRACE_DISABLE_INTS (i.e., trace_hardirqs_off()).

This is not necessary, because we must already be soft-disabled in the interrupt context, it also may be causing crashes in the irq tracing code to re-enter as an nmi. Replace it with a warning to ensure that soft-interrupts are still disabled.

Fixes 7c0482e3d055 ("powerpc/irq: Fix another case of lazy IRQ state getting out of sync")
[bwh: Backported to 3.16: adjust context]
---
 arch/powerpc/kernel/entry_64.S | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
arch/powerpc/kernel/entry_64.S +7 -3
@@ -885,9 +885,13 @@ restore_irq_off:
 	beq	1f
 	rlwinm	r7,r7,0,~PACA_IRQ_HARD_DIS
 	stb	r7,PACAIRQHAPPENED(r13)
-1:	li	r0,0
-	stb	r0,PACASOFTIRQEN(r13);
-	TRACE_DISABLE_INTS
+1:
+#if defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_BUG)
+	/* The interrupt should not have soft enabled. */
+	lbz	r7,PACASOFTIRQEN(r13)
+1:	tdnei	r7,0
+	EMIT_BUG_ENTRY 1b,__FILE__,__LINE__,BUGFLAG_WARNING
+#endif
 	b	do_restore
 
 	/*
#84 lore raw

PATCH 79/410 ASoC: nuc900: Fix a loop timeout test

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Dan Carpenter <[email protected]>

commit 65a12b3aafed5fc59f4ce41b22b752b1729e6701 upstream.

We should be finishing the loop with timeout set to zero but because this is a post-op we finish with timeout == -1.

Fixes 1082e2703a2d ("ASoC: NUC900/audio: add nuc900 audio driver support")
---
 sound/soc/nuc900/nuc900-ac97.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/nuc900/nuc900-ac97.c +2 -2
@@ -67,7 +67,7 @@ static unsigned short nuc900_ac97_read(s
 
 	/* polling the AC_R_FINISH */
 	while (!(AUDIO_READ(nuc900_audio->mmio + ACTL_ACCON) & AC_R_FINISH)
-								&& timeout--)
+								&& --timeout)
 		mdelay(1);
 
 	if (!timeout) {
@@ -121,7 +121,7 @@ static void nuc900_ac97_write(struct snd
 
 	/* polling the AC_W_FINISH */
 	while ((AUDIO_READ(nuc900_audio->mmio + ACTL_ACCON) & AC_W_FINISH)
-								&& timeout--)
+								&& --timeout)
 		mdelay(1);
 
 	if (!timeout)
#85 lore raw

PATCH 80/410 rcutorture/configinit: Fix build directory error message

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: SeongJae Park <[email protected]>

commit 2adfa4210f8f35cdfb4e08318cc06b99752964c2 upstream.

The 'configinit.sh' script checks the format of optional argument for the build directory, printing an error message if the format is not valid. However, the error message uses the wrong variable, indicating an empty string even though the user entered a non-empty (but erroneous) string. This commit fixes the script to use the correct variable.

Fixes c87b9c601ac8 ("rcutorture: Add KVM-based test framework")
---
 tools/testing/selftests/rcutorture/bin/configinit.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/rcutorture/bin/configinit.sh +1 -1
@@ -51,7 +51,7 @@ then
 			mkdir $builddir
 		fi
 	else
-		echo Bad build directory: \"$builddir\"
+		echo Bad build directory: \"$buildloc\"
 		exit 2
 	fi
 fi
#86 lore raw

PATCH 81/410 rcutorture/kvm.sh: Use consistent help text for --qemu-args

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: SeongJae Park <[email protected]>

commit 8dcd6f3fe206c0bb8996e59386a04027b1c2fb9b upstream.

The '--qemu-args' option's help text is wrongly copied from '--qemu-cmd' option and its argument type description message format is inconsistent with other arguments. This commit fixes the usage and type messages to be consistent with others.

Fixes e9ce640001c6 ("rcutorture: Add --qemu-args argument to kvm.sh")
[bwh: Backported to 3.16: adjust context]
---
 tools/testing/selftests/rcutorture/bin/kvm.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/rcutorture/bin/kvm.sh +2 -2
@@ -67,7 +67,7 @@ usage () {
 	echo "       --kversion vN.NN"
 	echo "       --mac nn:nn:nn:nn:nn:nn"
 	echo "       --no-initrd"
-	echo "       --qemu-args qemu-system-..."
+	echo "       --qemu-args qemu-arguments"
 	echo "       --qemu-cmd qemu-system-..."
 	echo "       --results absolute-pathname"
 	echo "       --torture rcu"
@@ -142,7 +142,7 @@ do
 		TORTURE_INITRD=""; export TORTURE_INITRD
 		;;
 	--qemu-args)
-		checkarg --qemu-args "-qemu args" $# "$2" '^-' '^error'
+		checkarg --qemu-args "(qemu arguments)" $# "$2" '^-' '^error'
 		TORTURE_QEMU_ARG="$2"
 		shift
 		;;
#87 lore raw

PATCH 82/410 ima: relax requiring a file signature for new files with zero length

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Mimi Zohar <[email protected]>

commit b7e27bc1d42e8e0cc58b602b529c25cd0071b336 upstream.

Custom policies can require file signatures based on LSM labels. These files are normally created and only afterwards labeled, requiring them to be signed.

Instead of requiring file signatures based on LSM labels, entire filesystems could require file signatures. In this case, we need the ability of writing new files without requiring file signatures.

The definition of a "new" file was originally defined as any file with a length of zero. Subsequent patches redefined a "new" file to be based on the FILE_CREATE open flag. By combining the open flag with a file size of zero, this patch relaxes the file signature requirement.

Fixes 1ac202e978e1 ima: accept previously set IMA_NEW_FILE
---
 security/integrity/ima/ima_appraise.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
security/integrity/ima/ima_appraise.c +2 -1
@@ -198,7 +198,8 @@ int ima_appraise_measurement(int func, s
 		if (opened & FILE_CREATED)
 			iint->flags |= IMA_NEW_FILE;
 		if ((iint->flags & IMA_NEW_FILE) &&
-		    !(iint->flags & IMA_DIGSIG_REQUIRED))
+		    (!(iint->flags & IMA_DIGSIG_REQUIRED) ||
+		     (inode->i_size == 0)))
 			status = INTEGRITY_PASS;
 		goto out;
 	}
#88 lore raw

PATCH 83/410 RDMA/iwpm: Fix uninitialized error code in iwpm_send_mapinfo()

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Geert Uytterhoeven <[email protected]>

commit 302d6424e4a293a5761997e6c9fc3dfb1e4c355f upstream.

With gcc-4.1.2:

drivers/infiniband/core/iwpm_util.c: In function ‘iwpm_send_mapinfo’:
drivers/infiniband/core/iwpm_util.c:647: warning: ‘ret’ may be used uninitialized in this function

Indeed, if nl_client is not found in any of the scanned has buckets, ret will be used uninitialized.

Preinitialize ret to -EINVAL to fix this.

Fixes 30dc5e63d6a5ad24 ("RDMA/core: Add support for iWARP Port Mapper user space service")
[bwh: Backported to 3.16: adjust context]
---
 drivers/infiniband/core/iwpm_util.c | 1 +
 1 file changed, 1 insertion(+)
drivers/infiniband/core/iwpm_util.c +1 -0
@@ -513,6 +513,7 @@ int iwpm_send_mapinfo(u8 nl_client, int
 	}
 	skb_num++;
 	spin_lock_irqsave(&iwpm_mapinfo_lock, flags);
+	ret = -EINVAL;
 	for (i = 0; i < IWPM_HASH_BUCKET_SIZE; i++) {
 		hlist_for_each_entry(map_info, &iwpm_hash_bucket[i],
 				     hlist_node) {
#89 lore raw

PATCH 84/410 USB: serial: io_edgeport: fix possible sleep-in-atomic

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Jia-Ju Bai <[email protected]>

commit c7b8f77872c73f69a16528a9eb87afefcccdc18b upstream.

According to drivers/usb/serial/io_edgeport.c, the driver may sleep under a spinlock.
The function call path is:
edge_bulk_in_callback (acquire the spinlock)
process_rcvd_data

     process_rcvd_status
       change_port_settings
         send_iosp_ext_cmd
           write_cmd_usb
             usb_kill_urb --> may sleep

To fix it, the redundant usb_kill_urb() is removed from the error path after usb_submit_urb() fails.

This possible bug is found by my static analysis tool (DSAC) and checked by my code review.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 drivers/usb/serial/io_edgeport.c | 1 -
 1 file changed, 1 deletion(-)
drivers/usb/serial/io_edgeport.c +0 -1
@@ -2219,7 +2219,6 @@ static int write_cmd_usb(struct edgeport
 		/* something went wrong */
 		dev_err(dev, "%s - usb_submit_urb(write command) failed, status = %d\n",
 			__func__, status);
-		usb_kill_urb(urb);
 		usb_free_urb(urb);
 		atomic_dec(&CmdUrbs);
 		return status;
#90 lore raw

PATCH 85/410 media: bt8xx: Fix err 'bt878_probe()'

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Christophe JAILLET <[email protected]>

commit 45392ff6881dbe56d41ef0b17c2e576065f8ffa1 upstream.

This is odd to call 'pci_disable_device()' in an error path before a coresponding successful 'pci_enable_device()'.

Return directly instead.

Fixes 77e0be12100a ("V4L/DVB (4176): Bug-fix: Fix memory overflow")
---
 drivers/media/pci/bt8xx/bt878.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/pci/bt8xx/bt878.c +1 -2
@@ -433,8 +433,7 @@ static int bt878_probe(struct pci_dev *d
 	       bt878_num);
 	if (bt878_num >= BT878_MAX) {
 		printk(KERN_ERR "bt878: Too many devices inserted\n");
-		result = -ENOMEM;
-		goto fail0;
+		return -ENOMEM;
 	}
 	if (pci_enable_device(dev))
 		return -EIO;
#91 lore raw

PATCH 86/410 ath9k_htc: Add a sanity check in ath9k_htc_ampdu_action()

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Dan Carpenter <[email protected]>

commit 413fd2f5c0233d3cde391679b967c1f14cd2cb27 upstream.

Smatch generates a warning here:

    drivers/net/wireless/ath/ath9k/htc_drv_main.c:1688 ath9k_htc_ampdu_action()
    error: buffer overflow 'ista->tid_state' 8 <= 15

I don't know if it's a real bug or not but the other paths through this function all ensure that "tid" is less than ATH9K_HTC_MAX_TID (8) so checking here makes things more consistent.

Fixes fb9987d0f748 ("ath9k_htc: Support for AR9271 chipset.")
---
 drivers/net/wireless/ath/ath9k/htc_drv_main.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/wireless/ath/ath9k/htc_drv_main.c +4 -0
@@ -1672,6 +1672,10 @@ static int ath9k_htc_ampdu_action(struct
 		ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
 		break;
 	case IEEE80211_AMPDU_TX_OPERATIONAL:
+		if (tid >= ATH9K_HTC_MAX_TID) {
+			ret = -EINVAL;
+			break;
+		}
 		ista = (struct ath9k_htc_sta *) sta->drv_priv;
 		spin_lock_bh(&priv->tx.tx_lock);
 		ista->tid_state[tid] = AGGR_OPERATIONAL;
#92 lore raw

PATCH 87/410 media: exynos4-is: properly initialize frame format

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Arnd Bergmann <[email protected]>

commit 97913bcbe6da3957af27d9fdd76b3d97b99e6d6a upstream.

We copy the subdev frame format from a partially initialized structure, which is not entirely well-defined. Older compilers like gcc-4.4 can copy uninitialized stack data here and warn about it:

drivers/media/platform/exynos4-is/fimc-isp.c: In function 'fimc_isp_subdev_open':
drivers/media/platform/exynos4-is/fimc-isp.c:379: error: 'fmt.reserved[10u]' may be used uninitialized in this function drivers/media/platform/exynos4-is/fimc-isp.c:379: error: 'fmt.reserved[9u]' may be used uninitialized in this function
...
drivers/media/platform/exynos4-is/fimc-isp.c:379: error: 'fmt.reserved[0u]' may be used uninitialized in this function drivers/media/platform/exynos4-is/fimc-isp.c:379: error: 'fmt.xfer_func' may be used uninitialized in this function

On newer compilers, only the initialized fields get copied, but we should not rely on that, so this changes the code to zero-out the remaining fields first.

Fixes 9a761e436843 ("[media] exynos4-is: Add Exynos4x12 FIMC-IS driver")
---
 drivers/media/platform/exynos4-is/fimc-isp.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/media/platform/exynos4-is/fimc-isp.c +7 -7
@@ -366,16 +366,16 @@ static int fimc_isp_subdev_s_power(struc
 static int fimc_isp_subdev_open(struct v4l2_subdev *sd,
 				struct v4l2_subdev_fh *fh)
 {
-	struct v4l2_mbus_framefmt fmt;
 	struct v4l2_mbus_framefmt *format;
+	struct v4l2_mbus_framefmt fmt = {
+		.colorspace = V4L2_COLORSPACE_SRGB,
+		.code = fimc_isp_formats[0].mbus_code,
+		.width = DEFAULT_PREVIEW_STILL_WIDTH + FIMC_ISP_CAC_MARGIN_WIDTH,
+		.height = DEFAULT_PREVIEW_STILL_HEIGHT + FIMC_ISP_CAC_MARGIN_HEIGHT,
+		.field = V4L2_FIELD_NONE,
+	};
 
 	format = v4l2_subdev_get_try_format(fh, FIMC_ISP_SD_PAD_SINK);
-
-	fmt.colorspace = V4L2_COLORSPACE_SRGB;
-	fmt.code = fimc_isp_formats[0].mbus_code;
-	fmt.width = DEFAULT_PREVIEW_STILL_WIDTH + FIMC_ISP_CAC_MARGIN_WIDTH;
-	fmt.height = DEFAULT_PREVIEW_STILL_HEIGHT + FIMC_ISP_CAC_MARGIN_HEIGHT;
-	fmt.field = V4L2_FIELD_NONE;
 	*format = fmt;
 
 	format = v4l2_subdev_get_try_format(fh, FIMC_ISP_SD_PAD_SRC_FIFO);
#93 lore raw

PATCH 88/410 RDMA/cma: Use correct size when writing netlink stats

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Parav Pandit <[email protected]>

commit 7baaa49af3716fb31877c61f59b74d029ce15b75 upstream.

The code was using the src size when formatting the dst. They are almost certainly the same value but it reads wrong.

Fixes ce117ffac2e9 ("RDMA/cma: Export AF_IB statistics")
---
 drivers/infiniband/core/cma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/core/cma.c +1 -1
@@ -3637,7 +3637,7 @@ static int cma_get_id_stats(struct sk_bu
 					  RDMA_NL_RDMA_CM_ATTR_SRC_ADDR))
 				goto out;
 			if (ibnl_put_attr(skb, nlh,
-					  rdma_addr_size(cma_src_addr(id_priv)),
+					  rdma_addr_size(cma_dst_addr(id_priv)),
 					  cma_dst_addr(id_priv),
 					  RDMA_NL_RDMA_CM_ATTR_DST_ADDR))
 				goto out;
#94 lore raw

PATCH 89/410 pinctrl: Really force states during suspend/resume

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Florian Fainelli <[email protected]>

commit 981ed1bfbc6c4660b2ddaa8392893e20a6255048 upstream.

In case a platform only defaults a "default" set of pins, but not a "sleep" set of pins, and this particular platform suspends and resumes in a way that the pin states are not preserved by the hardware, when we resume, we would call pinctrl_single_resume() -> pinctrl_force_default() -> pinctrl_select_state() and the first thing we do is check that the pins state is the same as before, and do nothing.

In order to fix this, decouple the actual state change from pinctrl_select_state() and move it pinctrl_commit_state(), while keeping the p->state == state check in pinctrl_select_state() not to change the caller assumptions. pinctrl_force_sleep() and pinctrl_force_default() are updated to bypass the state check by calling pinctrl_commit_state().

[Linus Walleij]
The forced pin control states are currently only used in some pin controller drivers that grab their own reference to their own pins. This is equal to the pin control hogs: pins taken by pin control devices since there are no corresponding device in the Linux device hierarchy, such as memory controller lines or unused GPIO lines, or GPIO lines that are used orthogonally from the GPIO subsystem but pincontrol-wise managed as hogs (non-strict mode, allowing simultaneous use by GPIO and pin control). For this case forcing the state from the drivers' suspend()/resume() callbacks makes sense and should semantically match the name of the function.

Fixes 6e5e959dde0d ("pinctrl: API changes to support multiple states per device")
---
 drivers/pinctrl/core.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)
drivers/pinctrl/core.c +17 -7
@@ -977,19 +977,16 @@ struct pinctrl_state *pinctrl_lookup_sta
 EXPORT_SYMBOL_GPL(pinctrl_lookup_state);
 
 /**
- * pinctrl_select_state() - select/activate/program a pinctrl state to HW
+ * pinctrl_commit_state() - select/activate/program a pinctrl state to HW
  * @p: the pinctrl handle for the device that requests configuration
  * @state: the state handle to select/activate/program
  */
-int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)
+static int pinctrl_commit_state(struct pinctrl *p, struct pinctrl_state *state)
 {
 	struct pinctrl_setting *setting, *setting2;
 	struct pinctrl_state *old_state = p->state;
 	int ret;
 
-	if (p->state == state)
-		return 0;
-
 	if (p->state) {
 		/*
 		 * The set of groups with a mux configuration in the old state
@@ -1067,6 +1064,19 @@ unapply_new_state:
 
 	return ret;
 }
+
+/**
+ * pinctrl_select_state() - select/activate/program a pinctrl state to HW
+ * @p: the pinctrl handle for the device that requests configuration
+ * @state: the state handle to select/activate/program
+ */
+int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)
+{
+	if (p->state == state)
+		return 0;
+
+	return pinctrl_commit_state(p, state);
+}
 EXPORT_SYMBOL_GPL(pinctrl_select_state);
 
 static void devm_pinctrl_release(struct device *dev, void *res)
@@ -1235,7 +1245,7 @@ void pinctrl_unregister_map(struct pinct
 int pinctrl_force_sleep(struct pinctrl_dev *pctldev)
 {
 	if (!IS_ERR(pctldev->p) && !IS_ERR(pctldev->hog_sleep))
-		return pinctrl_select_state(pctldev->p, pctldev->hog_sleep);
+		return pinctrl_commit_state(pctldev->p, pctldev->hog_sleep);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(pinctrl_force_sleep);
@@ -1247,7 +1257,7 @@ EXPORT_SYMBOL_GPL(pinctrl_force_sleep);
 int pinctrl_force_default(struct pinctrl_dev *pctldev)
 {
 	if (!IS_ERR(pctldev->p) && !IS_ERR(pctldev->hog_default))
-		return pinctrl_select_state(pctldev->p, pctldev->hog_default);
+		return pinctrl_commit_state(pctldev->p, pctldev->hog_default);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(pinctrl_force_default);
#95 lore raw

PATCH 90/410 net/mlx4_core: Cleanup FMR unmapping flow

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Tariq Toukan <[email protected]>

commit fd4a3e2828b4ca35aef40e5bdc1ed7d87b3cb50a upstream.

Remove redundant and not essential operations in fmr unmap/free. According to device spec, in FMR unmap it is sufficient to set ownership bit to SW. This allows remapping afterwards.

Fixes 8ad11fb6b073 ("IB/mlx4: Implement FMRs")
---
 drivers/net/ethernet/mellanox/mlx4/mr.c | 40 +++++++++++++------------
 1 file changed, 21 insertions(+), 19 deletions(-)
drivers/net/ethernet/mellanox/mlx4/mr.c +21 -19
@@ -944,30 +944,16 @@ EXPORT_SYMBOL_GPL(mlx4_fmr_enable);
 void mlx4_fmr_unmap(struct mlx4_dev *dev, struct mlx4_fmr *fmr,
 		    u32 *lkey, u32 *rkey)
 {
-	struct mlx4_cmd_mailbox *mailbox;
-	int err;
-
 	if (!fmr->maps)
 		return;
 
-	fmr->maps = 0;
+	/* To unmap: it is sufficient to take back ownership from HW */
+	*(u8 *)fmr->mpt = MLX4_MPT_STATUS_SW;
 
-	mailbox = mlx4_alloc_cmd_mailbox(dev);
-	if (IS_ERR(mailbox)) {
-		err = PTR_ERR(mailbox);
-		pr_warn("mlx4_ib: mlx4_alloc_cmd_mailbox failed (%d)\n", err);
-		return;
-	}
+	/* Make sure MPT status is visible */
+	wmb();
 
-	err = mlx4_HW2SW_MPT(dev, NULL,
-			     key_to_hw_index(fmr->mr.key) &
-			     (dev->caps.num_mpts - 1));
-	mlx4_free_cmd_mailbox(dev, mailbox);
-	if (err) {
-		pr_warn("mlx4_ib: mlx4_HW2SW_MPT failed (%d)\n", err);
-		return;
-	}
-	fmr->mr.enabled = MLX4_MPT_EN_SW;
+	fmr->maps = 0;
 }
 EXPORT_SYMBOL_GPL(mlx4_fmr_unmap);
 
@@ -977,6 +963,22 @@ int mlx4_fmr_free(struct mlx4_dev *dev,
 
 	if (fmr->maps)
 		return -EBUSY;
+	if (fmr->mr.enabled == MLX4_MPT_EN_HW) {
+		/* In case of FMR was enabled and unmapped
+		 * make sure to give ownership of MPT back to HW
+		 * so HW2SW_MPT command will success.
+		 */
+		*(u8 *)fmr->mpt = MLX4_MPT_STATUS_SW;
+		/* Make sure MPT status is visible before changing MPT fields */
+		wmb();
+		fmr->mpt->length = 0;
+		fmr->mpt->start  = 0;
+		/* Make sure MPT data is visible after changing MPT status */
+		wmb();
+		*(u8 *)fmr->mpt = MLX4_MPT_STATUS_HW;
+		/* make sure MPT status is visible */
+		wmb();
+	}
 
 	ret = mlx4_mr_free(dev, &fmr->mr);
 	if (ret)
#96 lore raw

PATCH 91/410 drivers: video: fbdev: atmel_lcdfb.c: fix error return code

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Julia Lawall <[email protected]>

commit 6c131850eca653344c41d68ce87f3ab5a89af89e upstream.

Convert a zero return value on error to a negative one, as returned elsewhere in the function.

A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
(
if@p1 (\(ret < 0\|ret != 0\))
{ ... return ret; }
|
ret@p1 = 0
)
... when != ret = e1

    when != &ret

*if(...)
{
... when != ret = e2
when forall
return ret;
}

// </smpl>

---
 drivers/video/fbdev/atmel_lcdfb.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/video/fbdev/atmel_lcdfb.c +2 -0
@@ -1101,12 +1101,14 @@ static int atmel_lcdfb_of_init(struct at
 	timings = of_get_display_timings(display_np);
 	if (!timings) {
 		dev_err(dev, "failed to get display timings\n");
+		ret = -EINVAL;
 		goto put_display_node;
 	}
 
 	timings_np = of_find_node_by_name(display_np, "display-timings");
 	if (!timings_np) {
 		dev_err(dev, "failed to find display-timings node\n");
+		ret = -ENODEV;
 		goto put_display_node;
 	}
 
#97 lore raw

PATCH 92/410 video: fbdev: atmel_lcdfb: fix display-timings lookup

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Johan Hovold <[email protected]>

commit 9cb18db0701f6b74f0c45c23ad767b3ebebe37f6 upstream.

Fix child-node lookup during probe, which ended up searching the whole device tree depth-first starting at the parent rather than just matching on its children.

To make things worse, the parent display node was also prematurely freed.

Note that the display and timings node references are never put after a successful dt-initialisation so the nodes would leak on later probe deferrals and on driver unbind.

Fixes b985172b328a ("video: atmel_lcdfb: add device tree suport")
Cc Jean-Christophe PLAGNIOL-VILLARD <[email protected]>
Cc Nicolas Ferre <[email protected]>
Cc Alexandre Belloni <[email protected]>
---
 drivers/video/fbdev/atmel_lcdfb.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/video/fbdev/atmel_lcdfb.c +7 -1
@@ -1105,7 +1105,7 @@ static int atmel_lcdfb_of_init(struct at
 		goto put_display_node;
 	}
 
-	timings_np = of_find_node_by_name(display_np, "display-timings");
+	timings_np = of_get_child_by_name(display_np, "display-timings");
 	if (!timings_np) {
 		dev_err(dev, "failed to find display-timings node\n");
 		ret = -ENODEV;
@@ -1126,6 +1126,12 @@ static int atmel_lcdfb_of_init(struct at
 		fb_add_videomode(&fb_vm, &info->modelist);
 	}
 
+	/*
+	 * FIXME: Make sure we are not referencing any fields in display_np
+	 * and timings_np and drop our references to them before returning to
+	 * avoid leaking the nodes on probe deferral and driver unbind.
+	 */
+
 	return 0;
 
 put_timings_node:
#98 lore raw

PATCH 93/410 PM / devfreq: Propagate error from devfreq_add_device()

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Bjorn Andersson <[email protected]>

commit d1bf2d30728f310f72296b54f0651ecdb09cbb12 upstream.

Propagate the error of devfreq_add_device() in devm_devfreq_add_device() rather than statically returning ENOMEM. This makes it slightly faster to pinpoint the cause of a returned error.

Fixes 8cd84092d35e ("PM / devfreq: Add resource-managed function for devfreq device")
---
 drivers/devfreq/devfreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/devfreq/devfreq.c +1 -1
@@ -592,7 +592,7 @@ struct devfreq *devm_devfreq_add_device(
 	devfreq = devfreq_add_device(dev, profile, governor_name, data);
 	if (IS_ERR(devfreq)) {
 		devres_free(ptr);
-		return ERR_PTR(-ENOMEM);
+		return devfreq;
 	}
 
 	*ptr = devfreq;
#99 lore raw

PATCH 94/410 scsi: aacraid: Fix udev inquiry race condition

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Raghava Aditya Renukunta <[email protected]>

commit f4e8708d3104437fd7716e957f38c265b0c509ef upstream.

When udev requests for a devices inquiry string, it might create multiple threads causing a race condition on the shared inquiry resource string.

Created a buffer with the string for each thread.

Fixes 3bc8070fb75b3315 ([SCSI] aacraid: SMC vendor identification)

[bwh: Backported to 3.16:
- s/sup_adap_info->adapter_type_text/dev->supplement_adapter_info.AdapterTypeText/
- Adjust context]

---

drivers/scsi/aacraid/aachba.c +12 -5
@@ -770,8 +770,16 @@ static void setinqstr(struct aac_dev *de
 	memset(str, ' ', sizeof(*str));
 
 	if (dev->supplement_adapter_info.AdapterTypeText[0]) {
-		char * cp = dev->supplement_adapter_info.AdapterTypeText;
 		int c;
+		char *cp;
+		char *cname = kmemdup(dev->supplement_adapter_info.AdapterTypeText,
+				sizeof(dev->supplement_adapter_info.AdapterTypeText),
+								GFP_ATOMIC);
+
+		if (!cname)
+			return;
+
+		cp = cname;
 		if ((cp[0] == 'A') && (cp[1] == 'O') && (cp[2] == 'C'))
 			inqstrcpy("SMC", str->vid);
 		else {
@@ -780,8 +788,7 @@ static void setinqstr(struct aac_dev *de
 				++cp;
 			c = *cp;
 			*cp = '\0';
-			inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
-				   str->vid);
+			inqstrcpy(cname, str->vid);
 			*cp = c;
 			while (*cp && *cp != ' ')
 				++cp;
@@ -795,8 +802,8 @@ static void setinqstr(struct aac_dev *de
 			cp[sizeof(str->pid)] = '\0';
 		}
 		inqstrcpy (cp, str->pid);
-		if (c)
-			cp[sizeof(str->pid)] = c;
+
+		kfree(cname);
 	} else {
 		struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
 
#100 lore raw

PATCH 95/410 pktcdvd: Fix pkt_setup_dev() error path

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Bart Van Assche <[email protected]>

commit 5a0ec388ef0f6e33841aeb810d7fa23f049ec4cd upstream.

Commit 523e1d399ce0 ("block: make gendisk hold a reference to its queue") modified add_disk() and disk_release() but did not update any of the error paths that trigger a put_disk() call after disk->queue has been assigned. That introduced the following behavior in the pktcdvd driver if pkt_new_dev() fails:

Kernel BUG at 00000000e98fd882 [verbose debug info unavailable]

Since disk_release() calls blk_put_queue() anyway if disk->queue != NULL, fix this by removing the blk_cleanup_queue() call from the pkt_setup_dev() error path.

Fixes commit 523e1d399ce0 ("block: make gendisk hold a reference to its queue")
Cc Tejun Heo <[email protected]>
Cc Maciej S. Szmigiero <[email protected]>
---
 drivers/block/pktcdvd.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/block/pktcdvd.c +1 -3
@@ -2796,7 +2796,7 @@ static int pkt_setup_dev(dev_t dev, dev_
 	pd->pkt_dev = MKDEV(pktdev_major, idx);
 	ret = pkt_new_dev(pd, dev);
 	if (ret)
-		goto out_new_dev;
+		goto out_mem2;
 
 	/* inherit events of the host device */
 	disk->events = pd->bdev->bd_disk->events;
@@ -2814,8 +2814,6 @@ static int pkt_setup_dev(dev_t dev, dev_
 	mutex_unlock(&ctl_mutex);
 	return 0;
 
-out_new_dev:
-	blk_cleanup_queue(disk->queue);
 out_mem2:
 	put_disk(disk);
 out_mem:
#101 lore raw

PATCH 96/410 xtensa: fix futex_atomic_cmpxchg_inatomic

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Max Filippov <[email protected]>

commit ca47480921587ae30417dd234a9f79af188e3666 upstream.

Return 0 if the operation was successful, not the userspace memory value. Check that userspace value equals passed oldval, not itself. Don't update *uval if the value wasn't read from userspace memory.

This fixes process hang due to infinite loop in futex_lock_pi. It also fixes a bunch of glibc tests nptl/tst-mutexpi*.

---
 arch/xtensa/include/asm/futex.h | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)
arch/xtensa/include/asm/futex.h +10 -13
@@ -109,7 +109,6 @@ futex_atomic_cmpxchg_inatomic(u32 *uval,
 			      u32 oldval, u32 newval)
 {
 	int ret = 0;
-	u32 prev;
 
 	if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
 		return -EFAULT;
@@ -120,26 +119,24 @@ futex_atomic_cmpxchg_inatomic(u32 *uval,
 
 	__asm__ __volatile__ (
 	"	# futex_atomic_cmpxchg_inatomic\n"
-	"1:	l32i	%1, %3, 0\n"
-	"	mov	%0, %5\n"
-	"	wsr	%1, scompare1\n"
-	"2:	s32c1i	%0, %3, 0\n"
-	"3:\n"
+	"	wsr	%5, scompare1\n"
+	"1:	s32c1i	%1, %4, 0\n"
+	"	s32i	%1, %6, 0\n"
+	"2:\n"
 	"	.section .fixup,\"ax\"\n"
 	"	.align 4\n"
-	"4:	.long	3b\n"
-	"5:	l32r	%1, 4b\n"
-	"	movi	%0, %6\n"
+	"3:	.long	2b\n"
+	"4:	l32r	%1, 3b\n"
+	"	movi	%0, %7\n"
 	"	jx	%1\n"
 	"	.previous\n"
 	"	.section __ex_table,\"a\"\n"
-	"	.long 1b,5b,2b,5b\n"
+	"	.long 1b,4b\n"
 	"	.previous\n"
-	: "+r" (ret), "=&r" (prev), "+m" (*uaddr)
-	: "r" (uaddr), "r" (oldval), "r" (newval), "I" (-EFAULT)
+	: "+r" (ret), "+r" (newval), "+m" (*uaddr), "+m" (*uval)
+	: "r" (uaddr), "r" (oldval), "r" (uval), "I" (-EFAULT)
 	: "memory");
 
-	*uval = prev;
 	return ret;
 }
 
#102 lore raw

PATCH 97/410 signal/sh: Ensure si_signo is initialized in do_divide_error

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: "Eric W. Biederman" <[email protected]>

commit 0e88bb002a9b2ee8cc3cc9478ce2dc126f849696 upstream.

Set si_signo.

Cc Yoshinori Sato <[email protected]>
Cc Rich Felker <[email protected]>
Cc Paul Mundt <[email protected]>
Fixes 0983b31849bb ("sh: Wire up division and address error exceptions on SH-2A.")
---
 arch/sh/kernel/traps_32.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/sh/kernel/traps_32.c +2 -1
@@ -607,7 +607,8 @@ asmlinkage void do_divide_error(unsigned
 		break;
 	}
 
-	force_sig_info(SIGFPE, &info, current);
+	info.si_signo = SIGFPE;
+	force_sig_info(info.si_signo, &info, current);
 }
 #endif
 
#103 lore raw

PATCH 98/410 spi: imx: do not access registers while clocks disabled

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Stefan Agner <[email protected]>

commit d593574aff0ab846136190b1729c151c736727ec upstream.

Since clocks are disabled except during message transfer clocks are also disabled when spi_imx_remove gets called. Accessing registers leads to a freeeze at least on a i.MX 6ULL. Enable clocks before disabling accessing the MXC_CSPICTRL register.

Fixes 9e556dcc55774 ("spi: spi-imx: only enable the clocks when we start to transfer a message")
[bwh: Backported to 3.16: adjust context]
---
 drivers/spi/spi-imx.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/spi/spi-imx.c +13 -2
@@ -943,12 +943,23 @@ static int spi_imx_remove(struct platfor
 {
 	struct spi_master *master = platform_get_drvdata(pdev);
 	struct spi_imx_data *spi_imx = spi_master_get_devdata(master);
+	int ret;
 
 	spi_bitbang_stop(&spi_imx->bitbang);
 
+	ret = clk_enable(spi_imx->clk_per);
+	if (ret)
+		return ret;
+
+	ret = clk_enable(spi_imx->clk_ipg);
+	if (ret) {
+		clk_disable(spi_imx->clk_per);
+		return ret;
+	}
+
 	writel(0, spi_imx->base + MXC_CSPICTRL);
-	clk_unprepare(spi_imx->clk_ipg);
-	clk_unprepare(spi_imx->clk_per);
+	clk_disable_unprepare(spi_imx->clk_ipg);
+	clk_disable_unprepare(spi_imx->clk_per);
 	spi_master_put(master);
 
 	return 0;
#104 lore raw

PATCH 99/410 wl1251: check return from call to wl1251_acx_arp_ip_filter

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Colin Ian King <[email protected]>

commit ac1181c60822292176ab96912208ec9f9819faf8 upstream.

Currently the less than zero error check on ret is incorrect as it is checking a far earlier ret assignment rather than the return from the call to wl1251_acx_arp_ip_filter. Fix this by adding in the missing assginment.

Detected by CoverityScan, CID#1164835 ("Logically dead code")

Fixes 204cc5c44fb6 ("wl1251: implement hardware ARP filtering")
---
 drivers/net/wireless/ti/wl1251/main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/wireless/ti/wl1251/main.c +1 -2
@@ -1199,8 +1199,7 @@ static void wl1251_op_bss_info_changed(s
 		WARN_ON(wl->bss_type != BSS_TYPE_STA_BSS);
 
 		enable = bss_conf->arp_addr_cnt == 1 && bss_conf->assoc;
-		wl1251_acx_arp_ip_filter(wl, enable, addr);
-
+		ret = wl1251_acx_arp_ip_filter(wl, enable, addr);
 		if (ret < 0)
 			goto out_sleep;
 	}
#105 lore raw

PATCH 100/410 scsi: libsas: fix error when getting phy events

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Jason Yan <[email protected]>

commit 2b23d9509fd7174b362482cf5f3b5f9a2265bc33 upstream.

The intend purpose here was to goto out if smp_execute_task() returned error. Obviously something got screwed up. We will never get these link error statistics below:

~:/sys/class/sas_phy/phy-1:0:12 # cat invalid_dword_count 0
~:/sys/class/sas_phy/phy-1:0:12 # cat running_disparity_error_count 0
~:/sys/class/sas_phy/phy-1:0:12 # cat loss_of_dword_sync_count 0
~:/sys/class/sas_phy/phy-1:0:12 # cat phy_reset_problem_count 0

Obviously we should goto error handler if smp_execute_task() returns non-zero.

Fixes 2908d778ab3e ("[SCSI] aic94xx: new driver")
CC John Garry <[email protected]>
CC chenqilin <[email protected]>
CC chenxiang <[email protected]>
---
 drivers/scsi/libsas/sas_expander.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/libsas/sas_expander.c +1 -1
@@ -675,7 +675,7 @@ int sas_smp_get_phy_events(struct sas_ph
 	res = smp_execute_task(dev, req, RPEL_REQ_SIZE,
 			            resp, RPEL_RESP_SIZE);
 
-	if (!res)
+	if (res)
 		goto out;
 
 	phy->invalid_dword_count = scsi_to_u32(&resp[12]);
#106 lore raw

PATCH 101/410 scsi: aacraid: remove redundant setting of variable c

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Colin Ian King <[email protected]>

commit 91814744646351a470f256fbcb853fb5a7229a9f upstream.

A previous commit no longer stores the contents of c, so we now have a situation where c is being updated but the value is never read. Clean up the code by removing the now redundant setting of variable c.

Cleans up clang warning:
drivers/scsi/aacraid/aachba.c:943:3: warning: Value stored to 'c' is never read

Fixes f4e8708d3104 ("scsi: aacraid: Fix udev inquiry race condition")
---
 drivers/scsi/aacraid/aachba.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/scsi/aacraid/aachba.c +1 -4
@@ -796,11 +796,8 @@ static void setinqstr(struct aac_dev *de
 		while (*cp == ' ')
 			++cp;
 		/* last six chars reserved for vol type */
-		c = 0;
-		if (strlen(cp) > sizeof(str->pid)) {
-			c = cp[sizeof(str->pid)];
+		if (strlen(cp) > sizeof(str->pid))
 			cp[sizeof(str->pid)] = '\0';
-		}
 		inqstrcpy (cp, str->pid);
 
 		kfree(cname);
#107 lore raw

PATCH 102/410 usb: gadget: f_fs: Fix possibe deadlock

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Baolin Wang <[email protected]>

commit b3ce3ce02d146841af012d08506b4071db8ffde3 upstream.

When system try to close /dev/usb-ffs/adb/ep0 on one core, at the same time another core try to attach new UDC, which will cause deadlock as below scenario. Thus we should release ffs lock before issuing unregister_gadget_item().

[   52.642225] c1 ======================================================
[   52.642228] c1 [ INFO: possible circular locking dependency detected ]
[   52.642236] c1 4.4.6+ #1 Tainted: G        W  O
[   52.642241] c1 -------------------------------------------------------
[   52.642245] c1 usb ffs open/2808 is trying to acquire lock:
[   52.642270] c0  (udc_lock){+.+.+.}, at: [<ffffffc00065aeec>]
		usb_gadget_unregister_driver+0x3c/0xc8
[   52.642272] c1  but task is already holding lock:
[   52.642283] c0  (ffs_lock){+.+.+.}, at: [<ffffffc00066b244>]
		ffs_data_clear+0x30/0x140
[   52.642285] c1 which lock already depends on the new lock.
[   52.642287] c1
               the existing dependency chain (in reverse order) is:
[   52.642295] c0
	       -> #1 (ffs_lock){+.+.+.}:
[   52.642307] c0        [<ffffffc00012340c>] __lock_acquire+0x20f0/0x2238
[   52.642314] c0        [<ffffffc000123b54>] lock_acquire+0xe4/0x298
[   52.642322] c0        [<ffffffc000aaf6e8>] mutex_lock_nested+0x7c/0x3cc
[   52.642328] c0        [<ffffffc00066f7bc>] ffs_func_bind+0x504/0x6e8
[   52.642334] c0        [<ffffffc000654004>] usb_add_function+0x84/0x184
[   52.642340] c0        [<ffffffc000658ca4>] configfs_composite_bind+0x264/0x39c
[   52.642346] c0        [<ffffffc00065b348>] udc_bind_to_driver+0x58/0x11c
[   52.642352] c0        [<ffffffc00065b49c>] usb_udc_attach_driver+0x90/0xc8
[   52.642358] c0        [<ffffffc0006598e0>] gadget_dev_desc_UDC_store+0xd4/0x128
[   52.642369] c0        [<ffffffc0002c14e8>] configfs_write_file+0xd0/0x13c
[   52.642376] c0        [<ffffffc00023c054>] vfs_write+0xb8/0x214
[   52.642381] c0        [<ffffffc00023cad4>] SyS_write+0x54/0xb0
[   52.642388] c0        [<ffffffc000085ff0>] el0_svc_naked+0x24/0x28
[   52.642395] c0
              -> #0 (udc_lock){+.+.+.}:
[   52.642401] c0        [<ffffffc00011e3d0>] print_circular_bug+0x84/0x2e4
[   52.642407] c0        [<ffffffc000123454>] __lock_acquire+0x2138/0x2238
[   52.642412] c0        [<ffffffc000123b54>] lock_acquire+0xe4/0x298
[   52.642420] c0        [<ffffffc000aaf6e8>] mutex_lock_nested+0x7c/0x3cc
[   52.642427] c0        [<ffffffc00065aeec>] usb_gadget_unregister_driver+0x3c/0xc8
[   52.642432] c0        [<ffffffc00065995c>] unregister_gadget_item+0x28/0x44
[   52.642439] c0        [<ffffffc00066b34c>] ffs_data_clear+0x138/0x140
[   52.642444] c0        [<ffffffc00066b374>] ffs_data_reset+0x20/0x6c
[   52.642450] c0        [<ffffffc00066efd0>] ffs_data_closed+0xac/0x12c
[   52.642454] c0        [<ffffffc00066f070>] ffs_ep0_release+0x20/0x2c
[   52.642460] c0        [<ffffffc00023dbe4>] __fput+0xb0/0x1f4
[   52.642466] c0        [<ffffffc00023dd9c>] ____fput+0x20/0x2c
[   52.642473] c0        [<ffffffc0000ee944>] task_work_run+0xb4/0xe8
[   52.642482] c0        [<ffffffc0000cd45c>] do_exit+0x360/0xb9c
[   52.642487] c0        [<ffffffc0000cf228>] do_group_exit+0x4c/0xb0
[   52.642494] c0        [<ffffffc0000dd3c8>] get_signal+0x380/0x89c
[   52.642501] c0        [<ffffffc00008a8f0>] do_signal+0x154/0x518
[   52.642507] c0        [<ffffffc00008af00>] do_notify_resume+0x70/0x78
[   52.642512] c0        [<ffffffc000085ee8>] work_pending+0x1c/0x20
[   52.642514] c1
              other info that might help us debug this:
[   52.642517] c1  Possible unsafe locking scenario:
[   52.642518] c1        CPU0                    CPU1
[   52.642520] c1        ----                    ----
[   52.642525] c0   lock(ffs_lock);
[   52.642529] c0                                lock(udc_lock);
[   52.642533] c0                                lock(ffs_lock);
[   52.642537] c0   lock(udc_lock);
[   52.642539] c1
                      *** DEADLOCK ***
[   52.642543] c1 1 lock held by usb ffs open/2808:
[   52.642555] c0  #0:  (ffs_lock){+.+.+.}, at: [<ffffffc00066b244>]
		ffs_data_clear+0x30/0x140
[   52.642557] c1 stack backtrace:
[   52.642563] c1 CPU: 1 PID: 2808 Comm: usb ffs open Tainted: G
[   52.642565] c1 Hardware name: Spreadtrum SP9860g Board (DT)
[   52.642568] c1 Call trace:
[   52.642573] c1 [<ffffffc00008b430>] dump_backtrace+0x0/0x170
[   52.642577] c1 [<ffffffc00008b5c0>] show_stack+0x20/0x28
[   52.642583] c1 [<ffffffc000422694>] dump_stack+0xa8/0xe0
[   52.642587] c1 [<ffffffc00011e548>] print_circular_bug+0x1fc/0x2e4
[   52.642591] c1 [<ffffffc000123454>] __lock_acquire+0x2138/0x2238
[   52.642595] c1 [<ffffffc000123b54>] lock_acquire+0xe4/0x298
[   52.642599] c1 [<ffffffc000aaf6e8>] mutex_lock_nested+0x7c/0x3cc
[   52.642604] c1 [<ffffffc00065aeec>] usb_gadget_unregister_driver+0x3c/0xc8
[   52.642608] c1 [<ffffffc00065995c>] unregister_gadget_item+0x28/0x44
[   52.642613] c1 [<ffffffc00066b34c>] ffs_data_clear+0x138/0x140
[   52.642618] c1 [<ffffffc00066b374>] ffs_data_reset+0x20/0x6c
[   52.642621] c1 [<ffffffc00066efd0>] ffs_data_closed+0xac/0x12c
[   52.642625] c1 [<ffffffc00066f070>] ffs_ep0_release+0x20/0x2c
[   52.642629] c1 [<ffffffc00023dbe4>] __fput+0xb0/0x1f4
[   52.642633] c1 [<ffffffc00023dd9c>] ____fput+0x20/0x2c
[   52.642636] c1 [<ffffffc0000ee944>] task_work_run+0xb4/0xe8
[   52.642640] c1 [<ffffffc0000cd45c>] do_exit+0x360/0xb9c
[   52.642644] c1 [<ffffffc0000cf228>] do_group_exit+0x4c/0xb0
[   52.642647] c1 [<ffffffc0000dd3c8>] get_signal+0x380/0x89c
[   52.642651] c1 [<ffffffc00008a8f0>] do_signal+0x154/0x518
[   52.642656] c1 [<ffffffc00008af00>] do_notify_resume+0x70/0x78
[   52.642659] c1 [<ffffffc000085ee8>] work_pending+0x1c/0x20
[bwh: Backported to 3.16: adjust context]
---
 drivers/usb/gadget/f_fs.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/usb/gadget/f_fs.c +6 -2
@@ -2998,6 +2998,7 @@ done:
 static void ffs_closed(struct ffs_data *ffs)
 {
 	struct ffs_dev *ffs_obj;
+	struct config_item *ci;
 
 	ENTER();
 	ffs_dev_lock();
@@ -3015,8 +3016,11 @@ static void ffs_closed(struct ffs_data *
 	    || !ffs_obj->opts->func_inst.group.cg_item.ci_parent)
 		goto done;
 
-	unregister_gadget_item(ffs_obj->opts->
-			       func_inst.group.cg_item.ci_parent->ci_parent);
+	ci = ffs_obj->opts->func_inst.group.cg_item.ci_parent->ci_parent;
+	ffs_dev_unlock();
+
+	unregister_gadget_item(ci);
+	return;
 done:
 	ffs_dev_unlock();
 }
#108 lore raw

PATCH 103/410 usb: f_fs: Prevent gadget unbind if it is already unbound

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Hemant Kumar <[email protected]>

commit ce5bf9a50daf2d9078b505aca1cea22e88ecb94a upstream.

Upon usb composition switch there is possibility of ep0 file release happening after gadget driver bind. In case of composition switch from adb to a non-adb composition gadget will never gets bound again resulting into failure of usb device enumeration. Fix this issue by checking FFS_FL_BOUND flag and avoid extra gadget driver unbind if it is already done as part of composition switch.

This fixes adb reconnection error reported on Android running v4.4 and above kernel versions. Verified on Hikey running vanilla v4.15-rc7 + few out of tree Mali patches.

Reviewed-at: https://android-review.googlesource.com/#/c/582632/

Cc Felipe Balbi <[email protected]>
Cc Greg KH <[email protected]>
Cc Michal Nazarewicz <[email protected]>
Cc John Stultz <[email protected]>
Cc Dmitry Shmidt <[email protected]>
Cc Badhri <[email protected]>
Cc Android Kernel Team <[email protected]>
[AmitP: Cherry-picked it from android-4.14 and updated the commit log]
---
 drivers/usb/gadget/f_fs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/gadget/f_fs.c +2 -1
@@ -3019,7 +3019,8 @@ static void ffs_closed(struct ffs_data *
 	ci = ffs_obj->opts->func_inst.group.cg_item.ci_parent->ci_parent;
 	ffs_dev_unlock();
 
-	unregister_gadget_item(ci);
+	if (test_bit(FFS_FL_BOUND, &ffs->flags))
+		unregister_gadget_item(ci);
 	return;
 done:
 	ffs_dev_unlock();
#109 lore raw

PATCH 104/410 ext4: save error to disk in __ext4_grp_locked_error()

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Zhouyi Zhou <[email protected]>

commit 06f29cc81f0350261f59643a505010531130eea0 upstream.

In the function __ext4_grp_locked_error(), __save_error_info() is called to save error info in super block block, but does not sync that information to disk to info the subsequence fsck after reboot.

This patch writes the error information to disk. After this patch, I think there is no obvious EXT4 error handle branches which leads to "Remounting filesystem read-only" will leave the disk partition miss the subsequence fsck.

---
 fs/ext4/super.c | 1 +
 1 file changed, 1 insertion(+)
fs/ext4/super.c +1 -0
@@ -678,6 +678,7 @@ __acquires(bitlock)
 	}
 
 	ext4_unlock_group(sb, grp);
+	ext4_commit_super(sb, 1);
 	ext4_handle_error(sb);
 	/*
 	 * We only get here in the ERRORS_RO case; relocking the group
#110 lore raw

PATCH 105/410 drm/radeon: Add dpm quirk for Jet PRO (v2)

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Alex Deucher <[email protected]>

commit 239b5f64e12b1f09f506c164dff0374924782979 upstream.

Fixes stability issues.

v2: clamp sclk to 600 Mhz

---
 drivers/gpu/drm/radeon/si_dpm.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/radeon/si_dpm.c +5 -0
@@ -2974,6 +2974,11 @@ static void si_apply_state_adjust_rules(
 			max_sclk = 75000;
 			max_mclk = 80000;
 		}
+		if ((rdev->pdev->revision == 0xC3) ||
+		    (rdev->pdev->device == 0x6665)) {
+			max_sclk = 60000;
+			max_mclk = 80000;
+		}
 	}
 	/* Apply dpm quirks */
 	while (p && p->chip_device != 0) {
#111 lore raw

PATCH 106/410 x86/gart: Exclude GART aperture from vmcore

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Jiri Bohac <[email protected]>

commit 2a3e83c6f96c513f43ce5a8c9034608ea584a255 upstream.

On machines where the GART aperture is mapped over physical RAM /proc/vmcore contains the remapped range and reading it may cause hangs or reboots.

In the past, the GART region was added into the resource map, implemented by commit 56dd669a138c ("[PATCH] Insert GART region into resource map")

However, inserting the iomem_resource from the early GART code caused resource conflicts with some AGP drivers (bko#72201), which got avoided by reverting the patch in commit 707d4eefbdb3 ("Revert [PATCH] Insert GART region into resource map"). This revert introduced the /proc/vmcore bug.

The vmcore ELF header is either prepared by the kernel (when using the kexec_file_load syscall) or by the kexec userspace (when using the kexec_load syscall). Since we no longer have the GART iomem resource, the userspace kexec has no way of knowing which region to exclude from the ELF header.

Changes from v1 of this patch:
Instead of excluding the aperture from the ELF header, this patch makes /proc/vmcore return zeroes in the second kernel when attempting to read the aperture region. This is done by reusing the gart_oldmem_pfn_is_ram infrastructure originally intended to exclude XEN balooned memory. This works for both, the kexec_file_load and kexec_load syscalls.

[Note that the GART region is the same in the first and second kernels:
regardless whether the first kernel fixed up the northbridge/bios setting and mapped the aperture over physical memory, the second kernel finds the northbridge properly configured by the first kernel and the aperture never overlaps with e820 memory because the second kernel has a fake e820 map created from the crashkernel memory regions. Thus, the second kernel keeps the aperture address/size as configured by the first kernel.]

register_oldmem_pfn_is_ram can only register one callback and returns an error if the callback has been registered already. Since XEN used to be the only user of this function, it never checks the return value. Now that we have more than one user, I added a WARN_ON just in case agp, XEN, or any other future user of register_oldmem_pfn_is_ram were to step on each other's toes.

Fixes 707d4eefbdb3 ("Revert [PATCH] Insert GART region into resource map")
Cc Baoquan He <[email protected]>
Cc Toshi Kani <[email protected]>
Cc David Airlie <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Dave Young <[email protected]>
Cc Vivek Goyal <[email protected]>
[bwh: Backported to 3.16: adjust filename]
---
 arch/x86/kernel/aperture_64.c | 46 ++++++++++++++++++++++++++++++++++-
 arch/x86/xen/mmu.c            |  2 +-
 2 files changed, 46 insertions(+), 2 deletions(-)
arch/x86/kernel/aperture_64.c +45 -1
@@ -29,6 +29,7 @@
 #include <asm/dma.h>
 #include <asm/amd_nb.h>
 #include <asm/x86_init.h>
+#include <linux/crash_dump.h>
 
 /*
  * Using 512M as goal, in case kexec will load kernel_big
@@ -55,6 +56,33 @@ int fallback_aper_force __initdata;
 
 int fix_aperture __initdata = 1;
 
+#ifdef CONFIG_PROC_VMCORE
+/*
+ * If the first kernel maps the aperture over e820 RAM, the kdump kernel will
+ * use the same range because it will remain configured in the northbridge.
+ * Trying to dump this area via /proc/vmcore may crash the machine, so exclude
+ * it from vmcore.
+ */
+static unsigned long aperture_pfn_start, aperture_page_count;
+
+static int gart_oldmem_pfn_is_ram(unsigned long pfn)
+{
+	return likely((pfn < aperture_pfn_start) ||
+		      (pfn >= aperture_pfn_start + aperture_page_count));
+}
+
+static void exclude_from_vmcore(u64 aper_base, u32 aper_order)
+{
+	aperture_pfn_start = aper_base >> PAGE_SHIFT;
+	aperture_page_count = (32 * 1024 * 1024) << aper_order >> PAGE_SHIFT;
+	WARN_ON(register_oldmem_pfn_is_ram(&gart_oldmem_pfn_is_ram));
+}
+#else
+static void exclude_from_vmcore(u64 aper_base, u32 aper_order)
+{
+}
+#endif
+
 /* This code runs before the PCI subsystem is initialized, so just
    access the northbridge directly. */
 
@@ -436,8 +464,16 @@ int __init gart_iommu_hole_init(void)
 
 out:
 	if (!fix && !fallback_aper_force) {
-		if (last_aper_base)
+		if (last_aper_base) {
+			/*
+			 * If this is the kdump kernel, the first kernel
+			 * may have allocated the range over its e820 RAM
+			 * and fixed up the northbridge
+			 */
+			exclude_from_vmcore(last_aper_base, last_aper_order);
+
 			return 1;
+		}
 		return 0;
 	}
 
@@ -474,6 +510,14 @@ out:
 		return 0;
 	}
 
+	/*
+	 * If this is the kdump kernel _and_ the first kernel did not
+	 * configure the aperture in the northbridge, this range may
+	 * overlap with the first kernel's memory. We can't access the
+	 * range through vmcore even though it should be part of the dump.
+	 */
+	exclude_from_vmcore(aper_alloc, aper_order);
+
 	/* Fix up the north bridges */
 	for (i = 0; i < amd_nb_bus_dev_ranges[i].dev_limit; i++) {
 		int bus, dev_base, dev_limit;
arch/x86/xen/mmu.c +1 -1
@@ -2500,7 +2500,7 @@ void __init xen_hvm_init_mmu_ops(void)
 	if (is_pagetable_dying_supported())
 		pv_mmu_ops.exit_mmap = xen_hvm_exit_mmap;
 #ifdef CONFIG_PROC_VMCORE
-	register_oldmem_pfn_is_ram(&xen_oldmem_pfn_is_ram);
+	WARN_ON(register_oldmem_pfn_is_ram(&xen_oldmem_pfn_is_ram));
 #endif
 }
 #endif
#112 lore raw

PATCH 107/410 ahci: Remove Device ID for Intel Sunrise Point PCH

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: James Ralston <[email protected]>

commit 46319e13581a6c442b0a0e5a3bd5d9af4496f252 upstream.

This patch removes a duplicate AHCI-mode SATA Device ID for the Intel Sunrise Point PCH.

---
 drivers/ata/ahci.c | 1 -
 1 file changed, 1 deletion(-)
drivers/ata/ahci.c +0 -1
@@ -359,7 +359,6 @@ static const struct pci_device_id ahci_p
 	{ PCI_VDEVICE(INTEL, 0x9d05), board_ahci }, /* Sunrise Point-LP RAID */
 	{ PCI_VDEVICE(INTEL, 0x9d07), board_ahci }, /* Sunrise Point-LP RAID */
 	{ PCI_VDEVICE(INTEL, 0xa103), board_ahci }, /* Sunrise Point-H AHCI */
-	{ PCI_VDEVICE(INTEL, 0xa103), board_ahci }, /* Sunrise Point-H RAID */
 	{ PCI_VDEVICE(INTEL, 0xa105), board_ahci }, /* Sunrise Point-H RAID */
 	{ PCI_VDEVICE(INTEL, 0xa107), board_ahci }, /* Sunrise Point-H RAID */
 	{ PCI_VDEVICE(INTEL, 0xa10f), board_ahci }, /* Sunrise Point-H RAID */
#113 lore raw

PATCH 108/410 ahci: add new Intel device IDs

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Alexandra Yates <[email protected]>

commit 56e74338a535cbcc2f2da08b1ea1a92920194364 upstream.

Adding Intel codename Lewisburg platform device IDs for SATA.

---
 drivers/ata/ahci.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/ata/ahci.c +10 -0
@@ -332,6 +332,16 @@ static const struct pci_device_id ahci_p
 	{ PCI_VDEVICE(INTEL, 0x1f37), board_ahci_avn }, /* Avoton RAID */
 	{ PCI_VDEVICE(INTEL, 0x1f3e), board_ahci_avn }, /* Avoton RAID */
 	{ PCI_VDEVICE(INTEL, 0x1f3f), board_ahci_avn }, /* Avoton RAID */
+	{ PCI_VDEVICE(INTEL, 0xa182), board_ahci }, /* Lewisburg AHCI*/
+	{ PCI_VDEVICE(INTEL, 0xa202), board_ahci }, /* Lewisburg AHCI*/
+	{ PCI_VDEVICE(INTEL, 0xa184), board_ahci }, /* Lewisburg RAID*/
+	{ PCI_VDEVICE(INTEL, 0xa204), board_ahci }, /* Lewisburg RAID*/
+	{ PCI_VDEVICE(INTEL, 0xa186), board_ahci }, /* Lewisburg RAID*/
+	{ PCI_VDEVICE(INTEL, 0xa206), board_ahci }, /* Lewisburg RAID*/
+	{ PCI_VDEVICE(INTEL, 0x2822), board_ahci }, /* Lewisburg RAID*/
+	{ PCI_VDEVICE(INTEL, 0x2826), board_ahci }, /* Lewisburg RAID*/
+	{ PCI_VDEVICE(INTEL, 0xa18e), board_ahci }, /* Lewisburg RAID*/
+	{ PCI_VDEVICE(INTEL, 0xa20e), board_ahci }, /* Lewisburg RAID*/
 	{ PCI_VDEVICE(INTEL, 0x2823), board_ahci }, /* Wellsburg RAID */
 	{ PCI_VDEVICE(INTEL, 0x2827), board_ahci }, /* Wellsburg RAID */
 	{ PCI_VDEVICE(INTEL, 0x8d02), board_ahci }, /* Wellsburg AHCI */
#114 lore raw

PATCH 109/410 ahci: Add Device ID for Intel Sunrise Point PCH

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: "[email protected]" <[email protected]>

commit c5967b79ecabe2baca40658d9073e28b30d7f6cf upstream.

This patch adds missing AHCI RAID SATA Device IDs for the Intel Sunrise Point PCH.

---
 drivers/ata/ahci.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/ata/ahci.c +2 -0
@@ -368,8 +368,10 @@ static const struct pci_device_id ahci_p
 	{ PCI_VDEVICE(INTEL, 0x9d03), board_ahci }, /* Sunrise Point-LP AHCI */
 	{ PCI_VDEVICE(INTEL, 0x9d05), board_ahci }, /* Sunrise Point-LP RAID */
 	{ PCI_VDEVICE(INTEL, 0x9d07), board_ahci }, /* Sunrise Point-LP RAID */
+	{ PCI_VDEVICE(INTEL, 0xa102), board_ahci }, /* Sunrise Point-H AHCI */
 	{ PCI_VDEVICE(INTEL, 0xa103), board_ahci }, /* Sunrise Point-H AHCI */
 	{ PCI_VDEVICE(INTEL, 0xa105), board_ahci }, /* Sunrise Point-H RAID */
+	{ PCI_VDEVICE(INTEL, 0xa106), board_ahci }, /* Sunrise Point-H RAID */
 	{ PCI_VDEVICE(INTEL, 0xa107), board_ahci }, /* Sunrise Point-H RAID */
 	{ PCI_VDEVICE(INTEL, 0xa10f), board_ahci }, /* Sunrise Point-H RAID */
 
#115 lore raw

PATCH 110/410 ahci: Order SATA device IDs for codename Lewisburg

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Alexandra Yates <[email protected]>

commit 4d92f0099a06ef0e36c7673f7c090f1a448b2d1b upstream.

This change was to preserve the ascending order of device IDs. There was an exception with the first two Lewisburg device IDs to keep all device IDs of the same kind grouped by code name.

---
 drivers/ata/ahci.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/ata/ahci.c +10 -10
@@ -332,16 +332,6 @@ static const struct pci_device_id ahci_p
 	{ PCI_VDEVICE(INTEL, 0x1f37), board_ahci_avn }, /* Avoton RAID */
 	{ PCI_VDEVICE(INTEL, 0x1f3e), board_ahci_avn }, /* Avoton RAID */
 	{ PCI_VDEVICE(INTEL, 0x1f3f), board_ahci_avn }, /* Avoton RAID */
-	{ PCI_VDEVICE(INTEL, 0xa182), board_ahci }, /* Lewisburg AHCI*/
-	{ PCI_VDEVICE(INTEL, 0xa202), board_ahci }, /* Lewisburg AHCI*/
-	{ PCI_VDEVICE(INTEL, 0xa184), board_ahci }, /* Lewisburg RAID*/
-	{ PCI_VDEVICE(INTEL, 0xa204), board_ahci }, /* Lewisburg RAID*/
-	{ PCI_VDEVICE(INTEL, 0xa186), board_ahci }, /* Lewisburg RAID*/
-	{ PCI_VDEVICE(INTEL, 0xa206), board_ahci }, /* Lewisburg RAID*/
-	{ PCI_VDEVICE(INTEL, 0x2822), board_ahci }, /* Lewisburg RAID*/
-	{ PCI_VDEVICE(INTEL, 0x2826), board_ahci }, /* Lewisburg RAID*/
-	{ PCI_VDEVICE(INTEL, 0xa18e), board_ahci }, /* Lewisburg RAID*/
-	{ PCI_VDEVICE(INTEL, 0xa20e), board_ahci }, /* Lewisburg RAID*/
 	{ PCI_VDEVICE(INTEL, 0x2823), board_ahci }, /* Wellsburg RAID */
 	{ PCI_VDEVICE(INTEL, 0x2827), board_ahci }, /* Wellsburg RAID */
 	{ PCI_VDEVICE(INTEL, 0x8d02), board_ahci }, /* Wellsburg AHCI */
@@ -374,6 +364,16 @@ static const struct pci_device_id ahci_p
 	{ PCI_VDEVICE(INTEL, 0xa106), board_ahci }, /* Sunrise Point-H RAID */
 	{ PCI_VDEVICE(INTEL, 0xa107), board_ahci }, /* Sunrise Point-H RAID */
 	{ PCI_VDEVICE(INTEL, 0xa10f), board_ahci }, /* Sunrise Point-H RAID */
+	{ PCI_VDEVICE(INTEL, 0x2822), board_ahci }, /* Lewisburg RAID*/
+	{ PCI_VDEVICE(INTEL, 0x2826), board_ahci }, /* Lewisburg RAID*/
+	{ PCI_VDEVICE(INTEL, 0xa182), board_ahci }, /* Lewisburg AHCI*/
+	{ PCI_VDEVICE(INTEL, 0xa184), board_ahci }, /* Lewisburg RAID*/
+	{ PCI_VDEVICE(INTEL, 0xa186), board_ahci }, /* Lewisburg RAID*/
+	{ PCI_VDEVICE(INTEL, 0xa18e), board_ahci }, /* Lewisburg RAID*/
+	{ PCI_VDEVICE(INTEL, 0xa202), board_ahci }, /* Lewisburg AHCI*/
+	{ PCI_VDEVICE(INTEL, 0xa204), board_ahci }, /* Lewisburg RAID*/
+	{ PCI_VDEVICE(INTEL, 0xa206), board_ahci }, /* Lewisburg RAID*/
+	{ PCI_VDEVICE(INTEL, 0xa20e), board_ahci }, /* Lewisburg RAID*/
 
 	/* JMicron 360/1/3/5/6, match class to avoid IDE function */
 	{ PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
#116 lore raw

PATCH 111/410 Adding Intel Lewisburg device IDs for SATA

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Alexandra Yates <[email protected]>

commit f5bdd66c705484b4bc77eb914be15c1b7881fae7 upstream.

This patch complements the list of device IDs previously added for lewisburg sata.

---
 drivers/ata/ahci.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/ata/ahci.c +6 -0
@@ -365,15 +365,21 @@ static const struct pci_device_id ahci_p
 	{ PCI_VDEVICE(INTEL, 0xa107), board_ahci }, /* Sunrise Point-H RAID */
 	{ PCI_VDEVICE(INTEL, 0xa10f), board_ahci }, /* Sunrise Point-H RAID */
 	{ PCI_VDEVICE(INTEL, 0x2822), board_ahci }, /* Lewisburg RAID*/
+	{ PCI_VDEVICE(INTEL, 0x2823), board_ahci }, /* Lewisburg AHCI*/
 	{ PCI_VDEVICE(INTEL, 0x2826), board_ahci }, /* Lewisburg RAID*/
+	{ PCI_VDEVICE(INTEL, 0x2827), board_ahci }, /* Lewisburg RAID*/
 	{ PCI_VDEVICE(INTEL, 0xa182), board_ahci }, /* Lewisburg AHCI*/
 	{ PCI_VDEVICE(INTEL, 0xa184), board_ahci }, /* Lewisburg RAID*/
 	{ PCI_VDEVICE(INTEL, 0xa186), board_ahci }, /* Lewisburg RAID*/
 	{ PCI_VDEVICE(INTEL, 0xa18e), board_ahci }, /* Lewisburg RAID*/
+	{ PCI_VDEVICE(INTEL, 0xa1d2), board_ahci }, /* Lewisburg RAID*/
+	{ PCI_VDEVICE(INTEL, 0xa1d6), board_ahci }, /* Lewisburg RAID*/
 	{ PCI_VDEVICE(INTEL, 0xa202), board_ahci }, /* Lewisburg AHCI*/
 	{ PCI_VDEVICE(INTEL, 0xa204), board_ahci }, /* Lewisburg RAID*/
 	{ PCI_VDEVICE(INTEL, 0xa206), board_ahci }, /* Lewisburg RAID*/
 	{ PCI_VDEVICE(INTEL, 0xa20e), board_ahci }, /* Lewisburg RAID*/
+	{ PCI_VDEVICE(INTEL, 0xa252), board_ahci }, /* Lewisburg RAID*/
+	{ PCI_VDEVICE(INTEL, 0xa256), board_ahci }, /* Lewisburg RAID*/
 
 	/* JMicron 360/1/3/5/6, match class to avoid IDE function */
 	{ PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
#117 lore raw

PATCH 112/410 AHCI: Remove obsolete Intel Lewisburg SATA RAID device IDs

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Scott Lawson <[email protected]>

commit 8ba559fd09bcf4e87faad3efa465dacf04c076c9 upstream.

These PCI device IDs have been removed from the Intel Lewisburg design specification. They are no longer needed.

---
 drivers/ata/ahci.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/ata/ahci.c +0 -4
@@ -369,15 +369,11 @@ static const struct pci_device_id ahci_p
 	{ PCI_VDEVICE(INTEL, 0x2826), board_ahci }, /* Lewisburg RAID*/
 	{ PCI_VDEVICE(INTEL, 0x2827), board_ahci }, /* Lewisburg RAID*/
 	{ PCI_VDEVICE(INTEL, 0xa182), board_ahci }, /* Lewisburg AHCI*/
-	{ PCI_VDEVICE(INTEL, 0xa184), board_ahci }, /* Lewisburg RAID*/
 	{ PCI_VDEVICE(INTEL, 0xa186), board_ahci }, /* Lewisburg RAID*/
-	{ PCI_VDEVICE(INTEL, 0xa18e), board_ahci }, /* Lewisburg RAID*/
 	{ PCI_VDEVICE(INTEL, 0xa1d2), board_ahci }, /* Lewisburg RAID*/
 	{ PCI_VDEVICE(INTEL, 0xa1d6), board_ahci }, /* Lewisburg RAID*/
 	{ PCI_VDEVICE(INTEL, 0xa202), board_ahci }, /* Lewisburg AHCI*/
-	{ PCI_VDEVICE(INTEL, 0xa204), board_ahci }, /* Lewisburg RAID*/
 	{ PCI_VDEVICE(INTEL, 0xa206), board_ahci }, /* Lewisburg RAID*/
-	{ PCI_VDEVICE(INTEL, 0xa20e), board_ahci }, /* Lewisburg RAID*/
 	{ PCI_VDEVICE(INTEL, 0xa252), board_ahci }, /* Lewisburg RAID*/
 	{ PCI_VDEVICE(INTEL, 0xa256), board_ahci }, /* Lewisburg RAID*/
 
#118 lore raw

PATCH 113/410 ahci: Add PCI ids for Intel Bay Trail, Cherry Trail and Apollo Lake AHCI

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Hans de Goede <[email protected]>

commit 998008b779e424bd7513c434d0ab9c1268459009 upstream.

Add PCI ids for Intel Bay Trail, Cherry Trail and Apollo Lake AHCI SATA controllers. This commit is a preparation patch for allowing a different default sata link powermanagement policy for mobile chipsets.

---
 drivers/ata/ahci.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/ata/ahci.c +4 -0
@@ -376,6 +376,10 @@ static const struct pci_device_id ahci_p
 	{ PCI_VDEVICE(INTEL, 0xa206), board_ahci }, /* Lewisburg RAID*/
 	{ PCI_VDEVICE(INTEL, 0xa252), board_ahci }, /* Lewisburg RAID*/
 	{ PCI_VDEVICE(INTEL, 0xa256), board_ahci }, /* Lewisburg RAID*/
+	{ PCI_VDEVICE(INTEL, 0x0f22), board_ahci }, /* Bay Trail AHCI */
+	{ PCI_VDEVICE(INTEL, 0x0f23), board_ahci }, /* Bay Trail AHCI */
+	{ PCI_VDEVICE(INTEL, 0x22a3), board_ahci }, /* Cherry Trail AHCI */
+	{ PCI_VDEVICE(INTEL, 0x5ae3), board_ahci }, /* Apollo Lake AHCI */
 
 	/* JMicron 360/1/3/5/6, match class to avoid IDE function */
 	{ PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
#119 lore raw

PATCH 114/410 ahci: Add Intel Cannon Lake PCH-H PCI ID

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Mika Westerberg <[email protected]>

commit f919dde0772a894c693a1eeabc77df69d6a9b937 upstream.

Add Intel Cannon Lake PCH-H PCI ID to the list of supported controllers.

[bwh: Backported to 3.16: adjust context]
---
 drivers/ata/ahci.c | 1 +
 1 file changed, 1 insertion(+)
drivers/ata/ahci.c +1 -0
@@ -376,6 +376,7 @@ static const struct pci_device_id ahci_p
 	{ PCI_VDEVICE(INTEL, 0xa206), board_ahci }, /* Lewisburg RAID*/
 	{ PCI_VDEVICE(INTEL, 0xa252), board_ahci }, /* Lewisburg RAID*/
 	{ PCI_VDEVICE(INTEL, 0xa256), board_ahci }, /* Lewisburg RAID*/
+	{ PCI_VDEVICE(INTEL, 0xa356), board_ahci }, /* Cannon Lake PCH-H RAID */
 	{ PCI_VDEVICE(INTEL, 0x0f22), board_ahci }, /* Bay Trail AHCI */
 	{ PCI_VDEVICE(INTEL, 0x0f23), board_ahci }, /* Bay Trail AHCI */
 	{ PCI_VDEVICE(INTEL, 0x22a3), board_ahci }, /* Cherry Trail AHCI */
#120 lore raw

PATCH 115/410 ext4: correct documentation for grpid mount option

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Ernesto A. Fernández
<[email protected]>

commit 9f0372488cc9243018a812e8cfbf27de650b187b upstream.

The grpid option is currently described as being the same as nogrpid.

---
 Documentation/filesystems/ext4.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/filesystems/ext4.txt +1 -1
@@ -233,7 +233,7 @@ data_err=ignore(*)	Just print an error m
 data_err=abort		Abort the journal if an error occurs in a file
 			data buffer in ordered mode.
 
-grpid			Give objects the same group ID as their creator.
+grpid			New objects have the group ID of their parent.
 bsdgroups
 
 nogrpid		(*)	New objects have the group ID of their creator.
#121 lore raw

PATCH 116/410 arm: spear600: Add missing interrupt-parent of rtc

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Viresh Kumar <[email protected]>

commit 6ffb5b4f248fe53e0361b8cbc2a523b432566442 upstream.

The interrupt-parent of rtc was missing, add it.

Fixes 8113ba917dfa ("ARM: SPEAr: DT: Update device nodes")
---
 arch/arm/boot/dts/spear600.dtsi | 1 +
 1 file changed, 1 insertion(+)
arch/arm/boot/dts/spear600.dtsi +1 -0
@@ -194,6 +194,7 @@
 			rtc@fc900000 {
 				compatible = "st,spear600-rtc";
 				reg = <0xfc900000 0x1000>;
+				interrupt-parent = <&vic0>;
 				interrupts = <10>;
 				status = "disabled";
 			};
#122 lore raw

PATCH 117/410 arm: spear13xx: Fix dmas cells

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Viresh Kumar <[email protected]>

commit cdd10409914184c7eee5ae3e11beb890c9c16c61 upstream.

The "dmas" cells for the designware DMA controller need to have only 3 properties apart from the phandle: request line, src master and destination master. But the commit 6e8887f60f60 updated it incorrectly while moving from platform code to DT. Fix it.

Fixes 6e8887f60f60 ("ARM: SPEAr13xx: Pass generic DW DMAC platform data from DT")
---
 Documentation/devicetree/bindings/dma/snps-dma.txt | 2 +-
 arch/arm/boot/dts/spear1340.dtsi                   | 4 ++--
 arch/arm/boot/dts/spear13xx.dtsi                   | 6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)
Documentation/devicetree/bindings/dma/snps-dma.txt +1 -1
@@ -58,6 +58,6 @@ Example:
 		interrupts = <0 35 0x4>;
 		status = "disabled";
 		dmas = <&dmahost 12 0 1>,
-			<&dmahost 13 0 1 0>;
+			<&dmahost 13 1 0>;
 		dma-names = "rx", "rx";
 	};
arch/arm/boot/dts/spear1340.dtsi +2 -2
@@ -113,8 +113,8 @@
 				reg = <0xb4100000 0x1000>;
 				interrupts = <0 105 0x4>;
 				status = "disabled";
-				dmas = <&dwdma0 0x600 0 0 1>, /* 0xC << 11 */
-					<&dwdma0 0x680 0 1 0>; /* 0xD << 7 */
+				dmas = <&dwdma0 12 0 1>,
+					<&dwdma0 13 1 0>;
 				dma-names = "tx", "rx";
 			};
 
arch/arm/boot/dts/spear13xx.dtsi +3 -3
@@ -100,7 +100,7 @@
 			reg = <0xb2800000 0x1000>;
 			interrupts = <0 29 0x4>;
 			status = "disabled";
-			dmas = <&dwdma0 0 0 0 0>;
+			dmas = <&dwdma0 0 0 0>;
 			dma-names = "data";
 		};
 
@@ -283,8 +283,8 @@
 				#size-cells = <0>;
 				interrupts = <0 31 0x4>;
 				status = "disabled";
-				dmas = <&dwdma0 0x2000 0 0 0>, /* 0x4 << 11 */
-					<&dwdma0 0x0280 0 0 0>;  /* 0x5 << 7 */
+				dmas = <&dwdma0 4 0 0>,
+					<&dwdma0 5 0 0>;
 				dma-names = "tx", "rx";
 			};
 
#123 lore raw

PATCH 118/410 arm: spear13xx: Fix spics gpio controller's warning

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Viresh Kumar <[email protected]>

commit f8975cb1b8a36d0839b6365235778dd9df1d04ca upstream.

This fixes the following warning by also sending the flags argument for gpio controllers:

Property 'cs-gpios', cell 6 is not a phandle reference in /ahb/apb/spi@e0100000

Fixes 8113ba917dfa ("ARM: SPEAr: DT: Update device nodes")
---
 arch/arm/boot/dts/spear1310-evb.dts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/boot/dts/spear1310-evb.dts +1 -1
@@ -345,7 +345,7 @@
 			spi0: spi@e0100000 {
 				status = "okay";
 				num-cs = <3>;
-				cs-gpios = <&gpio1 7 0>, <&spics 0>, <&spics 1>;
+				cs-gpios = <&gpio1 7 0>, <&spics 0 0>, <&spics 1 0>;
 
 				stmpe610@0 {
 					compatible = "st,stmpe610";
#124 lore raw

PATCH 119/410 mtd: nand: Fix nand_do_read_oob() return value

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Miquel Raynal <[email protected]>

commit 87e89ce8d0d14f573c068c61bec2117751fb5103 upstream.

Starting from commit 041e4575f034 ("mtd: nand: handle ECC errors in OOB"), nand_do_read_oob() (from the NAND core) did return 0 or a negative error, and the MTD layer expected it.

However, the trend for the NAND layer is now to return an error or a positive number of bitflips. Deciding which status to return to the user belongs to the MTD layer.

Commit e47f68587b82 ("mtd: check for max_bitflips in mtd_read_oob()") brought this logic to the mtd_read_oob() function while the return value coming from nand_do_read_oob() (called by the ->_read_oob() hook) was left unchanged.

Fixes e47f68587b82 ("mtd: check for max_bitflips in mtd_read_oob()")
---
 drivers/mtd/nand/nand_base.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/mtd/nand/nand_base.c +4 -1
@@ -1837,6 +1837,7 @@ static int nand_write_oob_syndrome(struc
 static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
 			    struct mtd_oob_ops *ops)
 {
+	unsigned int max_bitflips = 0;
 	int page, realpage, chipnr;
 	struct nand_chip *chip = mtd->priv;
 	struct mtd_ecc_stats stats;
@@ -1897,6 +1898,8 @@ static int nand_do_read_oob(struct mtd_i
 				nand_wait_ready(mtd);
 		}
 
+		max_bitflips = max_t(unsigned int, max_bitflips, ret);
+
 		readlen -= len;
 		if (!readlen)
 			break;
@@ -1922,7 +1925,7 @@ static int nand_do_read_oob(struct mtd_i
 	if (mtd->ecc_stats.failed - stats.failed)
 		return -EBADMSG;
 
-	return  mtd->ecc_stats.corrected - stats.corrected ? -EUCLEAN : 0;
+	return max_bitflips;
 }
 
 /**
#125 lore raw

PATCH 120/410 crypto: af_alg - whitelist mask and type

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Stephan Mueller <[email protected]>

commit bb30b8848c85e18ca7e371d0a869e94b3e383bdf upstream.

The user space interface allows specifying the type and mask field used to allocate the cipher. Only a subset of the possible flags are intended for user space. Therefore, white-list the allowed flags.

In case the user space caller uses at least one non-allowed flag, EINVAL is returned.

[bwh: Backported to 3.16: We don't have a CRYPTO_ALG_INTENRAL flag and
didn't blacklist it here]

---

crypto/af_alg.c +5 -0
@@ -149,6 +149,7 @@ EXPORT_SYMBOL_GPL(af_alg_release_parent)
 
 static int alg_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
 {
+	const u32 allowed = CRYPTO_ALG_KERN_DRIVER_ONLY;
 	struct sock *sk = sock->sk;
 	struct alg_sock *ask = alg_sk(sk);
 	struct sockaddr_alg *sa = (void *)uaddr;
@@ -156,6 +157,10 @@ static int alg_bind(struct socket *sock,
 	void *private;
 	int err;
 
+	/* If caller uses non-allowed flag, return error. */
+	if ((sa->salg_feat & ~allowed) || (sa->salg_mask & ~allowed))
+		return -EINVAL;
+
 	if (sock->state == SS_CONNECTED)
 		return -EINVAL;
 
#126 lore raw

PATCH 121/410 crypto: hash - introduce crypto_hash_alg_has_setkey()

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Eric Biggers <[email protected]>

commit cd6ed77ad5d223dc6299fb58f62e0f5267f7e2ba upstream.

Templates that use an shash spawn can use crypto_shash_alg_has_setkey() to determine whether the underlying algorithm requires a key or not. But there was no corresponding function for ahash spawns. Add it.

Note that the new function actually has to support both shash and ahash algorithms, since the ahash API can be used with either.

---
 crypto/ahash.c                 | 11 +++++++++++
 include/crypto/internal/hash.h |  2 ++
 2 files changed, 13 insertions(+)
crypto/ahash.c +11 -0
@@ -630,5 +630,16 @@ struct hash_alg_common *ahash_attr_alg(s
 }
 EXPORT_SYMBOL_GPL(ahash_attr_alg);
 
+bool crypto_hash_alg_has_setkey(struct hash_alg_common *halg)
+{
+	struct crypto_alg *alg = &halg->base;
+
+	if (alg->cra_type != &crypto_ahash_type)
+		return crypto_shash_alg_has_setkey(__crypto_shash_alg(alg));
+
+	return __crypto_ahash_alg(alg)->setkey != NULL;
+}
+EXPORT_SYMBOL_GPL(crypto_hash_alg_has_setkey);
+
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("Asynchronous cryptographic hash type");
include/crypto/internal/hash.h +2 -0
@@ -91,6 +91,8 @@ static inline bool crypto_shash_alg_has_
 	return alg->setkey != shash_no_setkey;
 }
 
+bool crypto_hash_alg_has_setkey(struct hash_alg_common *halg);
+
 int crypto_init_ahash_spawn(struct crypto_ahash_spawn *spawn,
 			    struct hash_alg_common *alg,
 			    struct crypto_instance *inst);
#127 lore raw

PATCH 122/410 crypto: cryptd - pass through absence of ->setkey()

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Eric Biggers <[email protected]>

commit 841a3ff329713f796a63356fef6e2f72e4a3f6a3 upstream.

When the cryptd template is used to wrap an unkeyed hash algorithm, don't install a ->setkey() method to the cryptd instance. This change is necessary for cryptd to keep working with unkeyed hash algorithms once we start enforcing that ->setkey() is called when present.

---
 crypto/cryptd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
crypto/cryptd.c +2 -1
@@ -617,7 +617,8 @@ static int cryptd_create_hash(struct cry
 	inst->alg.finup  = cryptd_hash_finup_enqueue;
 	inst->alg.export = cryptd_hash_export;
 	inst->alg.import = cryptd_hash_import;
-	inst->alg.setkey = cryptd_hash_setkey;
+	if (crypto_shash_alg_has_setkey(salg))
+		inst->alg.setkey = cryptd_hash_setkey;
 	inst->alg.digest = cryptd_hash_digest_enqueue;
 
 	err = ahash_register_instance(tmpl, inst);
#128 lore raw

PATCH 123/410 crypto: hash - annotate algorithms taking optional key

In reply to Ben Hutchings

3.16.57-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Eric Biggers <[email protected]>

commit a208fa8f33031b9e0aba44c7d1b7e68eb0cbd29e upstream.

We need to consistently enforce that keyed hashes cannot be used without setting the key. To do this we need a reliable way to determine whether a given hash algorithm is keyed or not. AF_ALG currently does this by checking for the presence of a ->setkey() method. However, this is actually slightly broken because the CRC-32 algorithms implement ->setkey() but can also be used without a key. (The CRC-32 "key" is not actually a cryptographic key but rather represents the initial state. If not overridden, then a default initial state is used.)

Prepare to fix this by introducing a flag CRYPTO_ALG_OPTIONAL_KEY which indicates that the algorithm has a ->setkey() method, but it is not required to be called. Then set it on all the CRC-32 algorithms.

The same also applies to the Adler-32 implementation in Lustre.

Also, the cryptd and mcryptd templates have to pass through the flag from their underlying algorithm.

[bwh: Backported to 3.16:
- Drop changes to nonexistent drivers
- There's no CRYPTO_ALG_INTERNAL flag
- Adjust filenames]

---

arch/sparc/crypto/crc32c_glue.c +1 -0
@@ -133,6 +133,7 @@ static struct shash_alg alg = {
 		.cra_name		=	"crc32c",
 		.cra_driver_name	=	"crc32c-sparc64",
 		.cra_priority		=	SPARC_CR_OPCODE_PRIORITY,
+		.cra_flags		=	CRYPTO_ALG_OPTIONAL_KEY,
 		.cra_blocksize		=	CHKSUM_BLOCK_SIZE,
 		.cra_ctxsize		=	sizeof(u32),
 		.cra_alignmask		=	7,
arch/x86/crypto/crc32-pclmul_glue.c +1 -0
@@ -162,6 +162,7 @@ static struct shash_alg alg = {
 			.cra_name		= "crc32",
 			.cra_driver_name	= "crc32-pclmul",
 			.cra_priority		= 200,
+			.cra_flags		= CRYPTO_ALG_OPTIONAL_KEY,
 			.cra_blocksize		= CHKSUM_BLOCK_SIZE,
 			.cra_ctxsize		= sizeof(u32),
 			.cra_module		= THIS_MODULE,
arch/x86/crypto/crc32c-intel_glue.c +1 -0
@@ -240,6 +240,7 @@ static struct shash_alg alg = {
 		.cra_name		=	"crc32c",
 		.cra_driver_name	=	"crc32c-intel",
 		.cra_priority		=	200,
+		.cra_flags		=	CRYPTO_ALG_OPTIONAL_KEY,
 		.cra_blocksize		=	CHKSUM_BLOCK_SIZE,
 		.cra_ctxsize		=	sizeof(u32),
 		.cra_module		=	THIS_MODULE,
crypto/crc32.c +1 -0
@@ -133,6 +133,7 @@ static struct shash_alg alg = {
 		.cra_name		= "crc32",
 		.cra_driver_name	= "crc32-table",
 		.cra_priority		= 100,
+		.cra_flags		= CRYPTO_ALG_OPTIONAL_KEY,
 		.cra_blocksize		= CHKSUM_BLOCK_SIZE,
 		.cra_ctxsize		= sizeof(u32),
 		.cra_module		= THIS_MODULE,
crypto/crc32c_generic.c +1 -0
@@ -146,6 +146,7 @@ static struct shash_alg alg = {
 		.cra_name		=	"crc32c",
 		.cra_driver_name	=	"crc32c-generic",
 		.cra_priority		=	100,
+		.cra_flags		=	CRYPTO_ALG_OPTIONAL_KEY,
 		.cra_blocksize		=	CHKSUM_BLOCK_SIZE,
 		.cra_alignmask		=	3,
 		.cra_ctxsize		=	sizeof(struct chksum_ctx),
crypto/cryptd.c +2 -1
@@ -603,7 +603,8 @@ static int cryptd_create_hash(struct cry
 	if (err)
 		goto out_free_inst;
 
-	inst->alg.halg.base.cra_flags = CRYPTO_ALG_ASYNC;
+	inst->alg.halg.base.cra_flags = CRYPTO_ALG_ASYNC |
+		(alg->cra_flags & CRYPTO_ALG_OPTIONAL_KEY);
 
 	inst->alg.halg.digestsize = salg->digestsize;
 	inst->alg.halg.base.cra_ctxsize = sizeof(struct cryptd_hash_ctx);
drivers/crypto/bfin_crc.c +2 -1
@@ -514,7 +514,8 @@ static struct ahash_alg algs = {
 		.cra_driver_name	= DRIVER_NAME,
 		.cra_priority		= 100,
 		.cra_flags		= CRYPTO_ALG_TYPE_AHASH |
-						CRYPTO_ALG_ASYNC,
+						CRYPTO_ALG_ASYNC |
+						CRYPTO_ALG_OPTIONAL_KEY,
 		.cra_blocksize		= CHKSUM_BLOCK_SIZE,
 		.cra_ctxsize		= sizeof(struct bfin_crypto_crc_ctx),
 		.cra_alignmask		= 3,
drivers/staging/lustre/lustre/libcfs/linux/linux-crypto-adler.c +1 -0
@@ -123,6 +123,7 @@ static struct shash_alg alg = {
 		.cra_name		= "adler32",
 		.cra_driver_name	= "adler32-zlib",
 		.cra_priority		= 100,
+		.cra_flags		= CRYPTO_ALG_OPTIONAL_KEY,
 		.cra_blocksize		= CHKSUM_BLOCK_SIZE,
 		.cra_ctxsize		= sizeof(u32),
 		.cra_module		= THIS_MODULE,
include/linux/crypto.h +6 -0
@@ -95,6 +95,12 @@
 #define CRYPTO_ALG_KERN_DRIVER_ONLY	0x00001000
 
 /*
+ * Set if the algorithm has a ->setkey() method but can be used without
+ * calling it first, i.e. there is a default key.
+ */
+#define CRYPTO_ALG_OPTIONAL_KEY		0x00004000
+
+/*
  * Transform masks and values (for crt_flags).
  */
 #define CRYPTO_TFM_REQ_MASK		0x000fff00